# Automatic W-9s again

Last year I wrote an AppleScript that used PDFpenPro1 to automate the creation of W-9 forms for my business. These are the forms that clients often request to make themselves feel comfortable about paying you without withholding taxes. Yesterday was the first time I tried to use the script after switching to a new 27″ iMac and Mountain Lion. It failed, but I managed to fix it.

As originally written, the script had one tell application "Finder" block and one tell application "PDFpenPro" block. The failure was occurring inside the PDFpenPro block, so I assumed some recent update had changed PDFpenPro’s AppleScript dictionary. But after looking through the dictionary and not finding any differences, I went back and looked at the error message more carefully. Although the error was definitely identifying the error as being in a line in the PDFpenPro block, it was a Finder error: “Finder can’t get blahblahblah from document 1 of blahblahblah.” I decided the more likely cause was a change to the Finder.

In his comment on that old post, Ben Waldie recommended a change to the script so it wouldn’t use the Finder to get the paths to the template and filled-in W-9 documents. I had told myself at the time that I should follow his advice, but I never got around to it. With the script no longer working, it seemed like a good time to to give his suggestion a try. Not surprisingly, it worked. Here’s the new script:

applescript:
1:  set today to current date
2:  set dstamp to (month of today as text) & " " & (day of today as text) & ", " & (year of today as text)
3:
4:  set w9 to (path to home folder from user domain as text) & "Dropbox:Unified W9.pdf"
5:  set w9 to w9 as alias
6:
7:  tell application "Finder" to duplicate w9 to desktop
8:
9:  set neww9 to (path to desktop folder from user domain as text) & "Unified W9.pdf"
10:  set neww9 to neww9 as alias
11:
12:  tell application "PDFpenPro"
13:    open neww9
14:    set stamp to make new text imprint with properties ¬
15:      {rich text:dstamp, x position:410, y position:264, width:144, height:16} ¬
16:        at end of imprints of page 1 of document 1
17:    set font of attribute run 1 of rich text of stamp to "Helvetica"
18:    set size of attribute run 1 of rich text of stamp to 12
19:    set color of attribute run 1 of rich text of stamp to {0, 0, 0}
20:    save document 1
21:    quit
22:  end tell


The changes are in the setting of variables w9 in Lines 4-5 and neww9 in Lines 9-10. There is still a Finder command there in Line 7 but all it does is duplicate the template document to the Desktop. PDFpenPro then opens the Desktop copy and makes changes to it. This version of the script works under both Lion and Mountain Lion.

Which reminds me: with the new machine at work, it’s time to update my MacBook Air to Mountain Lion.

1. I’m pretty sure the script would work with the non-pro PDFpen, too, but I haven’t tried it.