Archive for January, 2008

Filemaker Pro AppleScript – Part 1

If you are a Filemaker Pro developer working on Macs will know that this versatile database has had AppleScript support built in for many years. It’s a versatile and simple way to extend the functionality of Filemaker Pro allowing you to perform complex scripting tasks within the application or even link Filemaker Pro to other applications.

If you’re coming to Filemaker Pro Applescript for the first time, these script samples will hopefully help you get started.

—–

Let’s assume we’ve built a Filemaker database called “mcContacts” with a table called “Contacts” and four fields: “First Name”, “Last Name”, “email” and “Postal Code”

You can download the sample database here

How to create a new record:

tell application "FileMaker Pro"

 create new record in database "mcContacts"

end tell

How to create a new record and insert content:

tell application "FileMaker Pro"

 set newRecord to create new record in database "mcContacts"

 tell newRecord

 	set cell "First Name" to "Henry"

 	set cell "Last Name" to "Higgins"

 	set cell "Postal Code" to "HH1 3HH"

 	set cell "email" to "hhiggins@email.com"

 end tell

end tell

How to modify the current record:

set newFirstName to "Horace"

set newLastName to "Walpole"

tell application "FileMaker Pro"

 set cell "First Name" of current record to newFirstName

 set cell "Last Name" of current record to newLastName

end tell

How to get and display information from a record:

tell application "FileMaker Pro"

 tell database "mcContacts"

 	set firstName to the contents of field "First Name" of current record

 	display dialog "First Name in this record is: " & firstName

 end tell

end tell

How to delete the current record:

tell application "FileMaker Pro"

 tell database "mcContacts"

 	delete current record --be careful, there's no warning

 end tell

end tell

How to search for a record:



tell application "FileMaker Pro"

 tell database "mcContacts"

 	show (every record whose cell "First Name" = "Henry")

 end tell

end tell

How to search for a record with multiple search terms:



tell application "FileMaker Pro"

 tell database "mcContacts"

 	show (every record whose cell "First Name" = "Henry" and cell "Last Name" = "Higgins")

 end tell

end tell

How to show all records:

tell application "FileMaker Pro"

 tell database "mcContacts"

 	show every record

 end tell

end tell

How to sort the current records:

tell application "FileMaker Pro"

 tell database "mcContacts"

 	sort layout "Contacts" by field "Last Name" in order ascending

 end tell

end tell

How to show a particular record:

tell application "FileMaker Pro"

 tell database "mcContacts"

 	show record 2

 end tell

end tell

Also useful – perform a menu command:

tell application "FileMaker Pro"

 do menu menu item "Hide Window" of menu "Window"

end tell

Also useful – perform a script:

tell application "FileMaker Pro"

 tell database "mcContacts"

 	do script "Test"

 end tell

end tell

Finally, how to get Filemaker to make the tea:

tell application "FileMaker Pro"

 tell Metaclarity CEO "Paul Tuckey"

 	go an make the tea with delay 0

 end tell

end tell

We hope this helps you get up and running with AppleScript and Filemaker Pro. Stay tuned – we’ll be publishing Part 2 very soon!

Filemaker Pro 9’s best, easy-to-use new features

Metaclarity’s core work is Filemaker Pro development and Web Development. When Filemaker Pro 9 came out we were really impressed by several new features.

If you’re a developer or a user and haven’t moved to Filemaker Pro 9 yet, we think these are compelling reasons to do so:

  • Conditional formatting! This is cool. It means a field can go red or yellow or whatever when a user enters invalid data. Sounds little – it’s very, very useful!
  • The installation of FileMaker Server and FileMaker Server Advanced used to be a serious headache. FileMaker have really simplified things and you should be able to get FileMaker Server up and running in about 20 minutes – though you might want to set an hour aside!!
  • Don’t want FileMaker Server? If you use a FileMaker Pro client to share your databases, you’re now allowed up to nine peer-to-peer connections again (it dropped to four in previous versions).
  • The Append to PDF command that allows you to bring together a wide range of layout data into a single PDF report.
  • Layout objects can now be set to resize automatically (and correctly!!) on screen.
  • Developers also have folders to store their scripts in – at last!
  • And best of all, is FileMaker Pro 9’s ability to connect to and use external SQL data sources. We use mySQL a lot for web development. This is going to change radically the way we integrate our clients’ office solutions with their web sites. And it’s going to be good!

It’s well worth a look: Filemaker Pro 9

Use BBEdit UNIX Filters to Format Javascript

Here’s a tip specifically for people who use BBEdit to write Javascript.

If you copy a lot of Javascript examples from the web you probably end up with code that hugs the left edge of your BBEdit window like this (for example):

var txt=""
function message()
{
try
{
adddlert("Hey There!")
}
catch(err)
{
txt="An error has occurred"
alert(txt)
}
}

But you want it indented and nicely formatted, right?

Well, we found a link on the web [ http://attaboy.tumblr.com/post/20570385 ] that sort of explained how to put together a BBEdit UNIX Filter to do just that, but we also bashed our brains out for about an hour before realising that to call a PHP Shell Script in a UNIX Filter you need to wrap this around the code:

#!/usr/bin/php
<?php
[... your code...]
?>

Obvious to some – not to all of us!!

So we’ve put together the complete script to format Javascript from BBEdit here for downloading:

http://www.metaclarity.com/dl/JavaScriptFormatPHP.zip

Unzip it and put it in this folder:
~/Library/Application Support/BBEdit/Unix Support/Unix Filters/

Select your “flat” Javascript in the BBEdit window. Run the filter (from the !# menu or from Palettes>UNIX Filters) and it should format your Javascript!

Good luck!