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.
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.
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…
On to FileMaker
Now you’re ready to write your script in FIleMaker. First you will create 3 variables for $title, $message and $subtitle.
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.
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.
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!
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!
Front End Developer / FileMaker 13 Certified Developer
The Scarpetta Group, Inc.
The Scarpetta Group, Inc. is a Platinum FileMaker Business Alliance Member, specializing in custom FileMaker solutions for desktop, iOS and web. Our expertise is understanding our clients’ needs and translating their requirements into successful software solutions that enhance their business, improve efficiency and streamline workflows. We accomplish this through years of project management, diverse skill sets and industry experience.
Whereas many development firms handle only FileMaker development, we leverage our web development strengths and vast knowledge of bringing FileMaker to the web to set us apart. With more than 15 years of experience, The Scarpetta Group has completed countless projects for small businesses to international Fortune 500 companies. These projects have ranged from single iPad applications using FileMaker Go to 100+ user management systems, CRMs, Content Management Systems, Custom PHP APIs and complex web applications.
In the last five years, The Scarpetta Group has grown from a single employee and a team of subcontractors to five full time developers and a team of subcontractors. In 2013 The Scarpetta Group began hosting a FileMaker Pro User Group that has proven to be very successful and considered to be one of the larger user groups in the Southeast.
No matter what data challenges your company faces, The Scarpetta Group has the expertise to lead you in the right direction with your data management and get your company on the road to efficiency. Contact us today.Website: scarpettagroup.com