This was a little disconcerting to see in my Twitter stream:

Nice. @TextExpander übergeek @drdrang has turned his attention to @PDFpen + AppleScript. Productivity nerds rejoice! smle.us/wFBGv9
  — Jean MacDonald (@macgenie) Thu Feb 2 2012

Übergeek? Really? I mean, I really like that script because it uses PDFpen to turn a tedious, 2-3 minute task into a one-step, 2-3 second task, but there isn’t much to it. The trickiest part was getting the syntax right for adding text to a PDF. How did I work that out? As I said, I stole it from this script,

 1:  -- This script allows the user to enter text to imprint on all pages.
 3:  tell application "PDFpenPro"
 4:    if (count documents) > 0 then
 5:      set dialogResult to display dialog "Enter text:" default answer "Draft"
 6:      if button returned of dialogResult is not null then
 7:        set theText to text returned of dialogResult
 8:        tell document 1
 9:          set imprintCount to 0
10:          set pageCount to count pages
11:          repeat with aPage in pages
12:            set theImprint to make new text imprint with properties {rich text:theText} at end of imprints of aPage
13:            set font of attribute run 1 of rich text of theImprint to "LucidaGrande-Bold"
14:            set size of attribute run 1 of rich text of theImprint to 30
15:            set color of theImprint to {1, 0, 0}
16:          end repeat
17:          return pageCount
18:        end tell
19:      end if
20:    end if
21:  end tell

which should look familiar to Jean. It’s called “Imprint All Pages With Text,” and it’s provided by Smile Software as an example of the kinds of thing you can do with PDFpen and PDFpenPro. See any resemblance between Lines 12-15 of that script and Lines 11-14 of mine?

11:    set stamp to make new text imprint with properties {rich text:dstamp, x position:410, y position:262, width:144, height:16} at end of imprints of page 1 of document 1
12:    set font of attribute run 1 of rich text of stamp to "Helvetica"
13:    set size of attribute run 1 of rich text of stamp to 12
14:    set color of attribute run 1 of rich text of stamp to {0, 0, 0}

I would never have been able to write my script without the example provided by Smile. I knew from PDFpenPro’s AppleScript dictionary that it had something called text imprints and that they had a rich text property, but I had no idea how to set and style the rich text until I saw the sample code.

By the way, this illustrates an important point. There are only two ways to write AppleScript code:

  1. Copy someone else’s and adapt it.
  2. Keep trying different syntax until something works.

Most of the time I have to use both approaches. Is it any wonder I hate AppleScript? I’ve been programming in it since the mid-90s and I still feel like a novice.

So anyway, there was nothing übergeeky about that script. No clever algorithms, no brilliant insight. I just had an idea for saving time, and I hammered away at the script until it worked.

Which isn’t to say I can’t be übergeeky in my real area of expertise. I’ve written several posts like that. And when I finally get around to writing my long-delayed post on 19th-century suspension bridges, fluxions, and the tenacity of iron—hinted at in this interview over at MacDrifter—the geekiness will be über indeed.