Archive for August 2015

Using AppleScript to add an OmniFocus action from FileMaker Pro

I use a FileMaker Pro Advanced (FMP) database to keep my client information in my family law practice. I also use OmniFocus (OF) as my task management application. I thought it would be handy to be able to add an action to OF from FMP. I set up fields in FMP for the action’s name, due date and due time. The action is assigned to a client folder in OF based on the client record currently in use in FMP.

The following AppleScript is triggered by the press of a button in FMP:



tell application "FileMaker Pro Advanced"

       — this is to ensure that no field is selected when the script is run. A value cannot pass from FMP to OF if the field is "active"
       tell layout "Client Information"
		go to it
	end tell
	tell layout "Layout #2"
		go to it
	end tell


	tell current record
              
		set ClientName to (cell "DirectoryName")
		set ActionDate to (cell "ActionDate")
		set ActionTime to (cell "ActionTime")
		set ActionName to (cell "ActionName")

		tell application "System Events"
			set DateAndTime to ActionDate & " " & ActionTime
			set dueDate to date DateAndTime as date
		end tell
	end tell
end tell

tell application "OmniFocus"
	tell default document
		set theProject to first flattened project where its name = ClientName
		tell theProject
			set newAction to make new task with properties {name:ActionName, due date:dueDate}
		end tell
	end tell
end tell

tell application "FileMaker Pro Advanced"

       tell current record
               set cell "ActionDate" to ""
               set cell "ActionTime" to ""
               set cell "ActionName" to ""
	       display dialog "OmniFocus Action Added to Client Folder: " & ClientName
        end tell
end tell


.
 

The following is a description of what the script does:

  1. The switching of layouts is done to ensure that no field is selected (otherwise an error occurs in the script). In my database, the script is toggled from layout “Layout #2”. the layout is toggled to layout “Client Information” and back to layout “Layout #2”
  2. The values of four FMP fields are are assigned to variables in the script.
  3. The date and time of the action are converted from a text format to a time format.
  4. In OF, the correct client folder is selected. (The script assumes that the folder in OF has already been created).
  5. In the now selected OF folder a new task is created with the properties: name and due date (which includes the time).
  6. Back in FMP, the fields for the action name, due date and due time are erased.
  7. A dialog is displayed to tell me that the script was successful.