<
 

Using Script Editor 1 2 3 

Here is a quick overview of how to write and save AppleScripts with Script Editor. I've geared it towards working with iTunes. For the examples, I've used Script Editor 2 in Panther; differences in older Script Editor are mentioned where necessary.
For more details, I recommend going through Apple's AppleScript Language Guide.

(Portions of this article have been re-printed in the O'Reilly book iPod & iTunes HACKS.)

Shake Hands with Script Editor

Script Editor is an application included with AppleScript that lets you write, test, and save AppleScripts. In OS X it is in Applications > AppleScript. In OS 9 you'll find it in Applications > Apple Extras > AppleScript.

When you run Script Editor and create a new Script Editor document (File > New) notice how similar it looks to a text editor like SimpleText or TextEdit:

shot of Script Editor

The main window is where you will type in command statements. In the above picture you can see the cursor telling you where text will appear.

The main window of every Script Editor document contains four buttons that affect that particular window:

Record - lets you start recording your actions in the Finder and any other AppleScript-aware applications, although not all of these applications are recordable (including iTunes).
Stop - stops recording, or if the script is running it will attempt to stop it. Control-period also aborts the running of a script.
Run - activates the current script.
Compile - ("Check Syntax" in older versions) Script Editor will check the script for correct syntax before running it; this does not check if the script actually works, just whether it's constructed properly.

Script Editor 2's toolbar is customizable with more commands, but these are the essentials.

Along the bottom of Script Editor are three tabs which determine what is displayed in the lower half of the window. "Description" contains a text description from the author of what the script does (I also use it for temporarily parking snippets of code or copy-and-pasted text). "Result" displays the last result computed by a script. "Event Log" is a running display showing the results of a running script and "logged" results; very handy for debugging.

For the purposes of this article we're going to create a simple script or two to use with iTunes. Then we'll go over how to save it.

Type this in your bare Script Editor window (use the "return" key to start a new line):

shot of Script Editor

(I have adjusted my Script Editor's text formatting, so your text may not appear exactly like the above.) When you first enter text into a Script Editor window it's only text. Now click on Compile (Check Syntax in older editors), and Script Editor will make sure the script's syntax is written correctly. If it is, Script Editor will compile it and format the text like so:

shot of Script Editor

Okay! We have a script which we can Run and Save. Let's discuss how to save it and what sort of script to save it as on the next page...

2 3 | next >
This column is printer-friendly.
home | scripts | tips & info | forum at iLounge | rssfeed rss
Site contents © 2001 - 2008 Doug Adams and weblished by Doug Adams, dougscripts AT mac DOT com. All rights reserved. Legal.
AppleScript, iTunes, and iPod are registered trademarks of Apple Inc.
This page was served using PHP. Be that as it may—whatever that means—this page was last modified by human hands on November 10, 2005.

"If classical music is the state-of-the-art, then the arts are in a sad state." - F. Zappa