AppleScript_ The Definitive Guide - Matt Neuburg [208]
% sudo launchctl load -w /System/Library/LaunchDaemons/eppc
.plist
To target a remote application, you have to specify the machine on which it is running. To do so, you use an eppc URL . You can learn a lot more about the format of this URL—indeed, you can easily create such a URL, suitable for targeting a remote application—through the choose remote application command (Chapter 21). For example, if I use choose remote application to select the Finder on my iBook in the next room, I get this result:
application "Finder" of machine "eppc://duck.local/?uid=501&pid=179"
The application specifier is followed by a machine specifier that uses an eppc URL with my iBook's Bonjour name as the first path element. Actual connection to this machine will require a username and password; you can supply these as part of the eppc URL using the format username:password@ just before the machine name. The question mark and the material that follows it is optional, but can be useful. The uid is the user number, and you're going to need this parameter if you want to target a particular user's applications when multiple users are logged in. The pid is the process number of this application, so it's redundant given that we are already targeting the process by name, and in any case this number can change if an application quits or the computer is restarted, so you will probably have no use for it (though you can certainly use it instead of the name if you like). You can also incorporate the machine specifier into the application specifier by putting the application name as a second path element after the machine name (if you do this with a literal specifier, decompilation will rewrite the specifier in canonical form).
So, here are some ways of targeting the Finder on my iBook:
tell application "Finder" of machine "eppc://duck.local"
-- puts up the username/password dialog
get name of every window
end tell
tell application "Finder" of machine "eppc://mattneub:teehee@duck.local"
-- avoids the username/password dialog
get name of every window
end tell
set s to "eppc://mattneub:teehee@duck.local/Finder"
-- incorporates machine specifier into application specifier
tell application s
get name of window 1
end tell
set s to "eppc://mattneub:teehee@192.168.0.4/Finder"
-- uses IP number instead of Bonjour name
tell application s
get name of window 1
end tell
set s to "eppc://mattneub:teehee@duck.local/?uid=501&pid=179"
-- uses pid instead of application name
tell application s
get name of window 1
end tell
If you use a variable rather than a literal to specify the target, a terms block referring to a local application may be needed to resolve terminology at compile time (see "Using Terms From" in Chapter 19). It wasn't needed in the previous examples, because name and window are defined in AppleScript itself (see "The 'aeut' Resource" in Chapter 20). If possible, it's probably a good idea to use a terms block in any case, because it is much faster to get the dictionary from a local copy of an application than to get it across a network, and besides, you probably don't want to bother forming the connection to the remote machine every time you compile the script. So, for example:
set s to "eppc://mattneub:teehee@duck.local/Finder?uid=501"
using terms from application "Finder"
tell application s
get name of every disk
-- {"OmniumGatherum", "Network", "SecretSharer", "Puma"}
end tell
end using terms from
Some scripting addition commands you call while targeting a remote application are run on the remote machine. For example:
tell application "Finder" of machine "eppc://duck.local"
say "Watson, come here, I want you."
end tell
Starting in Tiger, however, scripting addition commands that put up a user interface are disabled from operating remotely; this makes sense because there might be no one at the remote machine to dismiss a dialog: