1.3. Calculation and Repetition
Computers are good at calculation and repetition . Humans, on the other hand, are liable to calculate inaccurately, and all the more so in the face of repetitive activity, which can make them careless, bored, and
Here's an example straight off the Internet, where someone
on open folderList
repeat with aFolder in folderList
if kind of (info for aFolder) is "Folder" then
renameStuffIn(aFolder)
end if
end repeat
end open
on renameStuffIn(theFolder)
set ix to 0
tell application "Finder"
set folderName to name of theFolder
set allItems to (get every item of theFolder)
repeat with thisItem in allItems
set ix to ix + 1
set newName to folderName & ix
set name of thisItem to newName
end repeat
end tell
end renameStuffIn
The parameter
folderList
|
1.4. Reduction
Even when a task doesn't involve repetition and calculation, it may involve many steps. If you can get AppleScript to perform many or all of those steps, you reduce the number of steps
you
have to perform. This can make for a noticeable improvement in your relationship with your computer, even if you perform this task
Here's an example involving URLs. Often, working in some application, I see a URL that I'd like to "go to" in the approprate manner. If it's an
http
URL, my default browser should
The solution is an AppleScript program. I've assigned it a keyboard shortcut (ways of doing this are discussed in Chapter 2), so the procedure is this: select and copy the URL, then press the keyboard shortcut. That's a significant savings in time and trouble. Here's the script:
set theProc to (get path to frontmost
application as Unicode text)
tell application "Finder"
activate
delay 1 --
give time for clip to convert from Classic
set theURL to (get the clipboard as string)
end tell
ignoring application responses
try
open location theURL
end try
end ignoring
activate application theProc
The switch to the Finder is to force the clipboard contents to convert
|