AppleScript_ The Definitive Guide - Matt Neuburg [202]
Example
random number
set L to {}
repeat 10 times
if (random number 1) as boolean then
set end of L to "heads"
else
set end of L to "tails"
end if
end repeat
L -- {"heads", "tails", "heads", "heads", "heads",
"tails", "heads", "heads", "heads", "heads"}
Name
current date
Synopsis
now
now
Generates a date object corresponding to the current date and time.
Example
time string of (current date) -- "10:41:13 AM"
Name
time to GMT
Synopsis
time zone
time zone
Reports the time zone that has been set via the Date & Time preference pane, as an offset from Greenwich Mean Time, in seconds.
Example
(time to GMT) / hours -- -7.0
Name
delay
Synopsis
wait
wait
Pauses for a specified number of seconds. Starting with Panther, this number can be a real.
Example
delay 1
beep
Name
mount volume
Synopsis
AppleShare
AppleShare
Mounts an AppleShare volume (a machine where Personal File Sharing is turned on). The machine is specified as an afp URL string, such as is returned from the choose URL command. To avoid the dialog for choosing a particular volume, add the volume name as a second path element. To avoid the dialog asking for username and password, supply them as parameters or as part of the URL. A Windows server can be mounted using an smb URL. Returns a file URL (but no result if the volume is already mounted). If the syntax of the mount volume command is insufficiently flexible, consider using do shell script to call mount_afp.
Examples
-- this first one lets user choose, presents the "Select volumes to mount" dialog
set s to choose URL showing File servers
mount volume s as user name "mattneub" with password "teehee"
-- these next ones present no dialogs
mount volume "afp://matt%20neuburg:teehee@duck.local/OmniumGatherum"
mount volume "afp://duck.local/OmniumGatherum" ¬
as user name "matt neuburg" with password "teehee"
-- this one presents username/password dialog and volume dialog
mount volume "afp://duck.local"
Name
scripting components
Synopsis
list OSA components
list OSA components
Returns a list of strings giving the names of the installed OSA scripting components. One of these will be "AppleScript".
Name
open location
Synopsis
open a URL
open a URL
Given a URL string, opens the URL with the appropriate helper application. For an example, see "Reduction" in Chapter 1.
Chapter 22. Speed
There are people who worry about squeezing every last possible ounce of speed out of AppleScript. They like nothing better than to sit down with a script and find clever ways of rearranging or reexpressing it so as to make it run faster. They have developed ingenious tricks and devices to optimize AppleScript code for speed. They even hold little contests to see whose script can complete a given task fastest! Personally, I'm not a great believer in optimizing code, but it's certainly true, as a practical matter, that most AppleScript programmers, sooner or later, do become concerned about speed. You've developed a script, and it's working, but when it runs it's taking longer than you think it should. You want to know whether there's anything you can do to make your script faster.
A few general considerations will put speed into perspective:
Things are better than they used to be
AppleScript is a lot faster than it once was, not just because we're all using vastly quicker computers these days, but because the runtime engine has been made more efficient. AppleScript used to be downright sluggish, and this was very noticeable back in the old days when computers had floppy disk slots and less than 4MB of RAM (and we all had to clean the streets with our tongues on the way to school). That's no longer the case.
Interapplication communication is a bottleneck
AppleScript is all about communicating