Ruby, an AppleScript Alternative – Part 2Tweet
My intention in exploring an alternative was to find an option for scripting beyond AppleScript itself and to rewrite an AppleScript program that I was currently using. The original AppleScript code was written to turn down the volume upon shutdown, to enable a silent bootup process. You can read the who, what and why in the original post.
However, I’m getting ahead of myself. Before we dig into the original code and how to write the same application in Ruby, let me take some time to explain a few other things important concepts within AppleScript.
In order to work with a scriptable application (or aspects of the system that are scriptable), one first needs to know what is scritable and how to interact with the scriptable resource, an API of sorts. In AppleScript parlance this is know as the Apple event registry, also referred to as a dictionary.
Let’s look at a few examples – to open the dictionary for system related events, open the Script Editor, click on File / Open Dictionary, and browse to the “System Events.app” application. Scroll down to the Power Suite and you should see a listing similar to the Figure below, which shows information on the commands: logout, restart, shutdown and sleep.
Information is organized into suites, which are shown in the leftmost window. In the middle column are available commands for the Power Suite. There is a great deal more information available within the dictionary, however, I’ll save the detailed description for another day.
Scripting Additions are a mechanism for extending the functionality of AppleScript. There are any number of Scripting Additions available (google for scripting additions) from mathematical stuff to sending SMS messages. A good list of addtions can be found at osaxen.com.
A commonly used Scripting Addition, and one which is included by default, is Standard Additions. For example, to display a dialog box, you use the User Interaction Suite and the display dialog command as shown in the figure below. To bring up this dictionary from within the Script Editor, open a new dictionary and scroll to the Standard Additions entry.
The information covered up to this point will lead us to the next post, which will make it clear why I chose the dictionaries I did in the examples above. And with the next post we’ll begin to dig into some Ruby code to make a few things happen with Apple Events. Same bat time, same bat channel…