AppleScript_ The Definitive Guide - Matt Neuburg [196]
try
run script "get the ticks"
on error -- evidently it isn't installed
set jons to choose file with prompt "Please find Jon's Commands:"
set sa to path to scripting additions from user domain
tell application "Finder" to duplicate jons to sa
try
tell me to «event ascrgdut»
end try
end try
display dialog (run script "get the ticks") -- 1974834
Standard Scripting Addition Commands
The scripting addition commands present in a standard installation of Tiger (Mac OS X 10.4) are all implemented by the StandardAdditions scripting addition. You can consult the StandardAdditions dictionary to learn what commands it contains and to get the full details on their syntax, and it would be a waste of trees for me to repeat the information you'll find there. However, I'll list all the commands and provide some basic explanations and comments (and examples) that go beyond what the dictionary tells you. For most of these commands, where I or the dictionary might say "string," you should understand "or Unicode text," since StandardAdditions has been generally revised to be Unicode-savvy.
(For load script, store script, and run script, see "Compiled Script Files as Script Objects" in Chapter 8. For the POSIX file class, see "File and Alias" in Chapter 13 and "File Coercions" in Chapter 14. For do shell script, see Chapter 25. For digital hub scripting, folder actions, and CGI events, see Chapter 27.)
Dialogs
These scripting addition commands put up dialogs, thus providing a modicum of user interaction. The dialog will appear in whatever application is being targeted at the moment, or in the host application if no application is being targeted. They should not be used in an environment where no user interaction is allowed (for example, in a Unix osascript command). Recall (from "Errors" in Chapter 19) that the -128 ("User canceled") error thrown when the user clicks the Cancel button in one of these dialogs, if it percolates all the way up to AppleScript, does not normally result in an error dialog (though it will cause the script to terminate prematurely).
Noises
These commands produce sounds and modify sound settings.
File and Machine Information
The following commands provide information about a file or the system.
File Data
These commands perform sequential read and write of file data. ("Sequential" means that each read or write will start, by default, just after the last character read or written in the same session.)
The file data commands let you describe the file you want to operate on as either a file reference number returned by open for access, or a file specifier or alias. In the read example earlier, I capture a file reference number and use it throughout; in the write example, I start with a file specifier and use that instead. The open for access command will also take a pathname string, but other commands will not. So, this works:
set f to open for access ((path to desktop as string) & "testing")
close access f
And so does this:
set f to ((path to desktop as string) & "testing")
open for access f
close access alias f
But this doesn't:
set f to ((path to desktop as string) & "testing")
open for access f
close access f
-- error: Can't make "feathers:Users:mattneub:Desktop:testing" into type file
You should ensure sufficient error handling so as not to leave a file open (unlike all the examples thus far!). If you do accidentally leave a file open, you might have to quit the current application, such as the Script Editor, in order to close it. Script Debugger helps you here; it notifies you if you've left a file open, and permits you to close