image

AppleScript Book (First Edition)

 
 

These are errata, desiderata, updata, and miscellaneous shmata connected with the first edition of my AppleScript book. For the second edition, see here.

Contributors include Nelson Byrne, David Cortesi, John Gruber, Martin Orpen, Kem Tekinay, and John Zandbergen.

p. xviii
It might be nice to mention these web pages (i.e. my own web pages) as part of the contact information. At the very least, it would be nice to add a paragraph at the end of the Contact section, saying: “The author maintains a personal web site at http://www.tidbits.com/matt/, where you can download the code examples from the book as a text file, along with the AppleScript Studio example from Chapter 24.”
p. 3
A number of readers have written in to say that the scripts in this chapter didn’t work on their computer. Well, they’re not supposed to! It’s only the first chapter. We haven’t gotten to the part of the book where I teach you to use AppleScript; I’m simply showing you, for purposes of motivation and illustration, some ways in which I use AppleScript. These scripts run on my computer, not yours. Nyaah nyaah nyaah! Seriously, it might be nice to add a parenthesis at the end of the second paragraph: “(The example scripts in this chapter are mere examples, and are intended simply to be read in context. Many of them won’t work unaltered on any machine but mine; after you’ve read Part II and learned the AppleScript language, you’ll be able to adapt them to your own purposes.)”
p. 12
With the emergence of Office 2004, the entire scripting model for the Office apps has changed. This means that the scripts on this page must be revised; here is a new equivalent (you can also get this from the code examples textfile):
set thePath to POSIX path of (choose file)
tell application "Microsoft Excel"
  make new document
  set view of window 1 to normal view
end tell
set s to "ruby ~/Desktop/histoChart.ruby '" & thePath & "'"
do shell script s

tell application "Microsoft Excel"
  select range "A1:B30"
  set chartSheet to make new chart sheet at beginning of active workbook
  set c to active chart
  tell c
    set chart type to bar clustered
    set has title to true
    set caption of its chart title to "30 Most Frequent Words"
    set has legend to false
    apply data labels type data labels show label without legend key
  end tell
  repeat with axt in {category axis, series axis, value axis}
    repeat with ax in {primary axis, secondary axis}
      try
        tell (get axis c axis type axt which axis ax)
          set {has major gridlines, has minor gridlines, has title} ¬
            to {false, false, false}
        end tell
        set has axis c axis type axt axis group ax without axis exists
      end try
    end repeat
  end repeat
end tell
p. 14
The soap example seems to have broken since the publication of the book. To fix it, simply eliminate the "www." from the SOAPAction parameter. (Thanks to Tom McKenna for help with this.)
p. 68
In the last line, “is if” should be “as if”.
p. 156
In the first paragraph, instead of “Of course, the functionality has to be defined somewhere to begin with,” it might be nice to say this: “Of course, the new functionality has to be defined somewhere to begin with, and the old functionality will be lost unless it is assigned to another variable beforehand.” This will make it clear that this trick, while cute and perhaps even useful, can result in the loss of defined handler functionality; this should be obvious, just as assigning 4 to x causes the previous value of x to be lost, but some readers have suggested that it should be stated explicitly.
p. 156
After the first paragraph and the example, it would have been nice to point out that, since a list can hold values of any type, it is possible for a list to contain handlers. A useful application is as a way of deciding in real time what handler to call. Here’s an example (useless, but easily made useful) where the handler we call depends upon the user’s response to a question:
on hey()
  display dialog "hey hey"
end hey
on ho()
  display dialog "ho ho"
end ho
set L to {hey, ho} -- a list of handlers
set Ls to {"call hey", "call ho"}
set r to button returned of ¬
  (display dialog "What do you want me to do?" ¬
  buttons Ls)
repeat with i from 1 to (count Ls)
  if item i of Ls is r then
    set whatToDo to item i of L
    whatToDo() -- call a handler from the list
    return
  end ifend repeat
p. 169
I think I would prefer that the word “hardcoding” be hyphenated: “hard-coding”.
p. 158
I got a shock the other day when one of my favorite scripts in the whole book (the first script on this page) suddenly didn’t work. Had AppleScript changed in such a way as to break it? But then I remembered: scripting additions. Sure enough, I’d installed a scripting addition that had “stolen” the verb filter; changing that name to something else throughout the script fixed the problem. There’s a moral here. Perhaps more than one moral.
p. 159
At the end of the first paragraph, something slightly bizarre has happened; delete the phrase “vertical bar” so that it says “starts with the keyword script”. I think some sort of global search done by the publisher’s production staff at the last minute must have gone awry here; the error is not present in any copy they gave me for proofreading.
p. 197
The footnote referred to in the next-to-last paragraph has slipped to the next page. This is very difficult to prevent; it’s actually a well-known bug in FrameMaker, and has to be countered by manually page-breaking the entire manuscript at the last minute. On the whole, the book has been very well page-broken by the production staff.
p. 212
At the start of the third paragraph, “is not the same” should be “is not the same as”.
p. 223
In the discussion of repeat with … in, I probably should have stressed that the loop variable, being a reference, can be passed to a handler which can thus mutate in place the items of the original list; this is a common and elegant idiom and deserves explicit mention. Mutual references between this passage and the appropriate sections of chapters 8 and 10 would have been nice too. Example:
on dealWith(x)
  set contents of x to "ha"
end dealWith
set L to {"hey", "ho"}
repeat with anItem in L
  dealWith(anItem)
end repeat
L -- {"ha", "ha"}
p. 244
Just as differences can arise with the various possible international settings for date formats (see the next page, p. 245), so differences can arise with possible international settings for number formats. This page should be made more complete by pointing these out. For example, if your numbers are set to use a comma as the decimal separator, an expression like class of ("1.1" as number) isn’t going to work.
p. 259-260
This page claims that “end of” is always fast, but as it turns out, that’s not so. The line set end of L to i happens to be fast, but if you say instead set end of L to "howdy", it’s slow - I have no idea why. The solution given on these pages remains correct: for example, you can say set end of my L to "howdy" and presto, it’s fast again. So the upshot is, I have not quite guessed correctly what makes list access slow; but the general moral is correct, namely, when in doubt, use my in referring to any list (and you should always be in doubt).
p. 269
In the second code stretch, where the last line is:

set a to posixFile as alias

It should be:

set a to pf as alias
p. 271
The convert script needs parentheses in the third line:

set conv to do shell script ({"units", unit1, unit2} as string)
p. 351
The third script no longer works. I don’t know why not; perhaps, as a security measure, run script on a remote machine has been disabled. In any case, here’s a workaround that relies on a different trick for obtaining the location of an application on a remote machine (and of course I have put this new code into the code examples textfile):
set m to "eppc://mattneub:harhar@little-white-duck.local"
tell application "Finder" of machine m
  using terms from application "Finder"
    set s to get application file id "sevs" as string
    open item s
  end using terms from
end tell
set se to "System Events"
tell application se of machine m
  using terms from application "System Events"
    get every process
  end using terms from
end tell
p. 360
In the second paragraph, “with actually” should be “without actually”.
p. 424
It would have been nice to mention PreFab UI Browser here; see p. 358 for the URL. So, we’d have a paragraph at the end of the first section: “PreFab UI Browser, a GUI Scripting utility: http://www.prefab.com/uibrowser/index.html”.
p. 425
Probably should have listed Adobe FrameMaker among the scriptable applications. So, we’d have a paragraph at the end of the second section: “Adobe FrameMaker, a scriptable book layout application: http://www.adobe.com/products/framemaker/main.html”.

Back to Matt Neuburg’s Home Page

This page prepared August 16, 2012 by Matt Neuburg, phd = matt at tidbits dot com, using RubyFrontier. RubyFrontier is a port, written in the Ruby language, of the Web-site-creation features of UserLand Frontier. Works just like Frontier, but written in Ruby!
Download RubyFrontier from GitHub.