Applescript Notification from FileMaker


FileMaker developers (and other app developers) are always looking for better ways to communicate information to their users. System level notifications have proven to be an effective way of sending short ‘dissolving’ messages to users. These Notification messages show up in the top right corner of the users screen, make a little chime, hang around for a few seconds and then disappear so that the user’s screen doesn’t get too cluttered with information.

Some uses for these Notifications for FileMaker developers might be:

  • sending a message when a long script or process has been completed
  • displaying an error message
  • as an emphatic tool tip

Basically, wherever a script is currently employing a Show Custom Message step, a developer might consider replacing it with a Notification. The advantage of Notifications is that they are less disruptive to the user’s workflow. They go away after a short duration, hopefully having informed the user of what has happened (or didn’t happen).

One notable addition to Apple’s Mavericks (OS X 10.9) is the Notifications system. This capability is also available in Yosemite (OS X 10.10). Similar to Growl (which I have written about before here), Apple Notifications are addressable through Applescript. As you may recall, FileMaker Pro has a Perform Applescript step in its scripting tool chest. I have created a small demo database to illustrate how Apple Notifications can be sent from FileMaker Pro using Perform Applescript. This file will run in FileMaker Pro 12 or FileMaker Pro 13 and up.

Demo Database

Download Demo File here.

 applescript-message

Test Notification Script

To examine how this demo works, open the ‘Test Notification’ script in Manage Scripts.

Edit Script “Test Notification”

Copy this script into your own solution and edit the three Script Variables for

  1. $Body
  2. $SubTitle
  3. $Title
  4. $Sound – Optional to edit. See the comments in the script for optional sounds.

Map these values to fields or text in your own solution.

 edit-script-test-notification-.png

The Applescript generated

A developer in a hurry could conceivable skip most of this script and just edit their message directly into the following Applescript step. To do this, simply replace the script variables with fields or text in quotation marks.

"set notificationTitle to the \""&$Title&"\"¶
set notificationSubTitle to \""&$SubTitle&"\"¶
set notificationMessage to \""&$Body&"\"¶
display notification notificationMessage with title 
notificationTitle subtitle notificationSubTitle sound name \""&$Sound&"\"¶
Delay 1"
the-applescript-generated.png

Limitations

Beyond the obvious fact that you need to be running on a Macintosh running OS X 10.10 or better, I wish that:

  • it was possible to run a FMP URL back to FileMaker from the Notification message if the user clicked on it. A script with a script parameter could then do something in FileMaker useful to the user.
  • there was more control over how long the message hung around. Sometimes it is nice for the message to stay there until the user does something like click on it. That way the information is less likely to get missed.

I didn’t see anything in the Apple documentation about doing either of these things. Feedback welcomed.

 Sources

Update: 2014-11-02 Reader Scott Rose pointed out that I was confusing my Mavericks with my Yosemite.

“Note that these require 10.9 to work properly, not 10.10. Mavericks is 10.9. Yosemite is 10.10.”

Scott was correct on both counts.

  1. In the original article and demo file, I had misnamed Yosemite (OS X 10.10) as Mavericks (OS X 10.9)
  2. The new Notifications capability was in the earlier OS X version (10.9).

I had to re-read the sources to see that the new Notifications features had indeed showed up in Mavericks. I even tested it on a MacBook Air still running 10.9.


 

Update: 2014-11-02 I saw on Twitter feedback from Stephen Blackwell who suggested that this type of notification could also be done cross-platform, Mac and Windows, using Troi’s Dialog plug-in. Based on the screen shot of Troi’s ‘temporary flash dialogs’, they wouldn’t be as pretty as the native file system, but they would be cross-platform.
Advertisements

Comments are closed.

%d bloggers like this: