The Original FileMaker Community
Free Templates - Demo Apps - Video Tutorials -Samples - Help - 46000 Member Forum

The Leading Filemaker Developer Tools

Password protection and security…

AppleScript OS X Notifications from FileMaker Pro 13 – FileMaker Today


Occasionally, in development, I find that I need to provide some sort of user feedback regarding the completion of a script or to display information to the user and sometimes a custom dialog is not the best solution. And, me just being me, I want to do it in a very useful, efficient and also cool way.

FileMaker_Notification


OS X Yosemite notification generated by FileMaker Pro 13


 


Well, if your user is on a Mac running Yosemite, you’re in luck because FileMaker can run AppleScript natively which will allow you to control OS X apps.

[ Insert cool factor here… ] This will allow you to AppleScript OS X notifications from FileMaker.


If you’re not familiar with it, AppleScript is a scripting language created by Apple Inc. and built into Macintosh operating systems since OS 7. There are numerous resources to learn all about it from books to blogs. A simple google search returns many tutorials from beginner to advanced level AppleScripting.


That being said, you can combine some simple AppleScript with the Perform AppleScript() script step in FileMaker Pro to create a notification to the user. The AppleScript to create the notification requires a Title and a message but the subtitle is optional.


The AppleScript


Below is our base AppleScript to generate a notification in OS X Yosemite.

display notification “Hello world!” with title “New Notification” subtitle “From FileMaker” sound name “default” delay 1


In this example “Hello world!” is your notification’s message. “New Notification” is the title of your notification and “From FileMaker” is your subtitle. You also have the option to generate a sound for the notification. Default is usually the best idea here to ensure that every user gets a similar experience. I have specified “delay 1″ to ensure that the script has time to execute and trigger the notification.


Modify the Applescript


Before putting this into the calculation window of the script step in your FIleMaker script, you will need to add quotes, carriage returns  and commented quotes to the AppleScript so that your calculation evaluates properly for the AppleScript to execute.


First, the entire AppleScript needs to be encapsulated in double quotes. As you will notice, your message, title and subtitle are also in quotes. You must escape these quotes so that they are regarded as text and not evaluated as the end of the variable. So your script now looks like this…


NotificationCode_Modified


On to FileMaker


Now you’re ready to write your script in FIleMaker. First you will create 3 variables for $title, $message and $subtitle.


Notification_variables


Next, insert the “Perform AppleScript” script step, choose “Calculated AppleScript” and paste the modified AppleScript into the calculation window. You can save the script and do a test run with your static message to ensure that everything is jiving. You should see a notification like the one above provided you are on OS X Yosemite. (This may work for other versions of Mac OS, but they have not been tested or verified).


The next thing you’ll want to do is to alter the AppleScript to use your variables. This will make the script modular so that you can pass script parameters to the notification.


NotificationCode_Modified2


Test the script


And finally, you’ll need a way to trigger and set the parameters to the script. So create a button and set script parameters for your notification title, message and subtitle.


Wrap up


I can honestly think of a million times to use AppleScript OS X notifications from FileMaker in a solution to give the user a more “native app” feel on OS X (okay, maybe not a million, but a lot). I hope you’ve enjoyed this snippet and it has sparked your interest in AppleScript. Using the tools and technologies we have,  we can extend the usefulness and useability of FileMaker solutions we build and give a more polished approach to simple tasks.


Thanks for reading!

~Aaron


If you have any questions or would like to have assistance implementing these features in your solutions, please contact us at scarpettagroup.com Contact us!


Aaron Giard

Front End Developer / FileMaker 13 Certified Developer

The Scarpetta Group, Inc.

This email address is being protected from spambots. You need JavaScript enabled to view it.

twitter: @AaronGiard

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Privacy & Cookies Policy