This tutorial will show you some basic in using AppleScript and REALbasic. The AppleScript is offering users an intelligent mechanism to control applications, and access and modify information and documents. We can use it in REALbasic for example to play music in iTunes, display contact from Address Book etc.
How can we know that for example iTunes offers a option to play and pause the music using AppleScript? The answer is quite easy. To get the list of iTunes options available for AppleScript we must only drag and drop iTunes app into AppleScript Editor icon displayed in Dock. The Terminology window will open like on the screen below.

Open AppleScript Editor and write this code into this editor. Next Compile it and click on Run button. When everything will go good your iTunes should lunch and play the music. If it’s already running then it will only play the music.
1 2 3 | tell application "iTunes" play end tell |
We can also add more commands to our AppleScript file, like in this example. This code will return the number of files available in “Application” folder.
1 2 3 4 5 6 7 | tell application "Finder" if folder "Applications" of startup disk exists then return count files in folder "Applications" of startup disk else return 0 end if end tell |
There is also a option to add some parameters in “on run” event. This example runs the Growl Notification System and pass the growlDescription and growlTitle to GrowlHelperApp. If you like to know how to interact this kind of AppleScript with REALbasic then go to my tutorial Growl notification system for REALbasic.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | on run {growlDescription, growlTitle} tell application "GrowlHelperApp" set the allNotificationsList to ¬ {"Notification"} set the enabledNotificationsList to ¬ {"Notification"} register as application ¬ "Our application name" all notifications allNotificationsList ¬ default notifications enabledNotificationsList ¬ icon of application "Safari" notify with name ¬ "Notification" title ¬ growlTitle description ¬ growlDescription application name "Our application name" end tell end run |
Thats original!
Thank you Tom