Sep 11, '08 07:30:00AM • Contributed by: kholburn
After upgrading to Leopard, I found that when I was printing a web receipt, I had a number of duplicate 'Save PDF to Web Receipts Folder' options in the PDF menu of the Print dialog box. When testing the duplicates, the web receipts seemed to end up in different odd places.
This was in part due the fact that I had created an Automator workflow (see previous hint) for 10.4. In Leopard, there is a new built-in item ;Save PDF to Web Receipts Folder' that comes from this file: /Library » PDF Services » Save PDF to Web Receipts Folder.pdfworkflow. Control-click on the pdfworkflow file, and navigate into Contents, where you'll find the working part of this bundle, a python script named tool.
This script creates a folder Web Receipts folder in your user's Documents folder, and puts web receipts in there. I wanted to customize my receipts with the time embedded directly in the filename, and change where the receipts were saved. After digging around a bit, I found this article, which explains how to do both those things.
I customized the file slightly differently; read on to see my solution...
Following the linked directions, I made a copy of the 'Save PDF to Web Receipts' workflow, and renamed it 'Save PDF in Web Receipts (python).' I edited the CFBundleName attribute of the Contents » Info.plist and Contents » Resources » English.lproj » InfoPlist.strings files to reflect the new workflow name. It doesn't really matter what the name is, but it should be different from the distribution file, and it should remind you what it does when it appears in the menu. And, of course, it's less confusing if it matches the file name.
I edited the tool file, and modified the line that looks like this:
destDirectory = os.path.expanduser("~/Documents/Web Receipts/")
Edit the path in that line to your preferred save location. Instead of the changes in the linked article to add the date to the file name, I made the following changes. First, around line 9 (just below import sys), add this line:
from time import strftime
Next, around what was line 24, but is now line 25, and after the line that starts with (title, options..., add this line:
title = "%s_%s" % (strftime( "%y-%m-%d_%H:%M:%S_%z"), title)
If you're familiar with strftime, you can customise this line for yourself. This worked exactly as I had hoped, leaving me with just the problem of the Automator action with the same name as the stock function. The Automator workflow was in ~/Library » PDF Services » Save PDF to Web Receipts Folder.workflow. I renamed the workflow folder to 'Print PDF to Web Receipts (automator).workflow.' Inside the bundle, there were two files: Contents » Resources » English.lproj » InfoPlist.strings and Contents » Info.plist. I edited both of these to change the CFBundleName attribute to match the filename, and now I have different names for all of the PDF menu items (the stock version, my date-modified version, and the Automator action). BTW, the new Automator seems to object to the old Automator documents, and likes you to open them and save them in the new format to make them work.
It appears that the PDF Services menu takes its names from the Contents » Resources » English.lproj » InfoPlist.strings file in each workflow. Pablo's web page suggests deleting the Resources folder, which I guess forces the menu to get the name from the Contents » Info.plist file instead. I prefer not to delete the Resources folder, but edit the file instead.
[robg adds: I tested this, and it works as described. I did, however, make a few changes. First, I created the copy of the existing python workflow in my user's ~/Library » PDF Services folder, so that I wouldn't have to worry about losing it if the system folder were ever rewritten. I then made all the described edits to that copy of the workflow. The only downside to this is that my entry appears at the bottom of the PDF Services menu, but that's only a slight annoyance.
I also changed the date and time format (in Terminal, man strftime will show you the various options), ending up with "%Y-%m-%d [%H.%M.%S]". Note that the Finder won't allow you to put a colon in a filename, so the version in the hint will come out with slashes between the hours, minutes, and seconds. I also left out the time zone offset (%z), as I don't have any need for that information. You can test your format in Terminal before committing it by typing date +"%Y-%m-%d [%H.%M.%S]" -- this will display the current date and time in the specified format.
The final change I made was to use a different separator between the time stamp and the name of the saved page -- just replace the underscore in "%s_%s" with whatever you like; I used "%s | %s", but you could just as easily use a space if you don't need a visual separator.]
