AppleScript_ The Definitive Guide - Matt Neuburg [207]
Specifying an application's name can be trickier than you might suppose. Back in the pre-Mac OS X days, typing the name of an application could be a maddening and tedious exercise. BBEdit's name wasn't "BBEdit"; it was "BBEdit 6.5". Excel's name was "Microsoft Excel". Frontier's name was "UserLand Frontier?", and you'd better not omit that "?" (and good luck remembering how to type it). Fortunately, if you got the name wrong, AppleScript would put up a File Open dialog giving you a chance to locate the application, and the correct name would then be substituted in your script. I remember I often used to supply a false name deliberately, such as tell application "xxx", just to get this dialog, because locating the application through the dialog was faster than trying to type (let alone remember) its "real" name.
With the coming of Mac OS X, things got even worse. The File Open dialog was replaced by a Choose Application dialog asking "Where is... ?" and listing all your applications; this dialog is slow to open and impossibly sluggish to navigate. For the programmer, the horror of this dialog becomes an incentive to enter the application's name correctly to begin with. At the same time, applications often contrive to disguise their real names. For example, Excel's name is "Excel" in both the Application menu and the Dock, but its real name is "Microsoft Excel". Before Tiger, that's what you had to type in order to specify it. In Tiger, though, you can specify an application by its short name, such as "Excel"; on compilation, provided the application is running, it will be found and the long name will be substituted.
Script editor applications now generally provide shortcuts for entering application names. In Script Editor, if an application is listed in the Library palette, you can select it and click the New Script button (in the palette's toolbar) to create a new script containing a tell block targeting that application. Script Debugger helps even more: there's a Recent Applications palette similar to Script Editor's Library window; every dictionary window contains a Paste Tell button; you can drag an application's icon into a script window or onto Script Debugger's icon to get a tell block targeting it; and there's a Paste Tell menu item, which lists all currently running scriptable applications and all applications whose dictionary you've recently viewed. Thus there is usually no need to type an application's name manually in order to target it.
Specifying a full pathname should not usually be necessary, but can sometimes be useful; for example, it could be a way to distinguish two versions of the same application on your machine . Unfortunately, this trick doesn't work if one version is already running. For example, I have FileMaker Pro version 7 and FileMaker Pro version 5.5. This script is meant to launch version 5.5, but it misbehaves if version 7 is already running (I regard this as a bug in AppleScript):
tell application "gromit:Users:matt2:Info Process:FileMaker 5.5:FileMaker Pro.app"
launch
get version -- "7.0v3"
end tell
Remote Applications
A remote application is an application running on a different computer from the script, or on the same computer but under a different user already logged in (through Fast User Switching ). Communication is performed over IP (not AppleTalk , as in the past); this has the advantage that it works over the Internet. Thanks to Bonjour (formerly called Rendezvous), a machine on the local network can be specified by name. On the target computer, Remote Apple Events must first be turned on; this can be done in the Sharing preference pane.
Tip
Worried about the insecurity of Remote Apple Events being left on all the time? (It requires only a password, and anyone can use choose remote application to see what processes are running without a password.) If you can get into a remote machine via ssh (which can be set to use the far more secure public-private key authentication method), you may be able to turn on Remote