One useful feature of OS X is the built in PDF handling. It is always easy to export a file as a PDF, and to do some basic editing of PDF files. A post on Mac OS X Hints today got me looking at some customizations. The hint is that creating an alias in the proper directory adds an item to the PDF menu. This can be done through Finder, or through the command line:
cd ~/Libary/PDF\ Services
ln -s ~/path/ "descriptive_alias"
You may have to create the directory
~/Libary/PDF Services. Some people recommend using the directory
/Libary/PDF Services, but this is bad style unless you really want the change to be universal. Even if you are the only user on the computer, it is safer to use the
Library folder under your user account.
When looking in the
/Libary/PDF Services directory, I noticed that the contents are just Automator workflows. This means it is easy for non-programmers to customize the behavior. One option that I somehow hadn’t noticed before today is
Save PDF to Web Receipts Folder.pdfworkflow. With online billing this is incredibly useful. I typically use the “Save PDF as” option, saving the PDF in this year’s receipts directory, with the date as a prefix. This makes receipts for monthly bills easy to find. I looked at “Save PDF to Web Receipts Folder” to see how easy it would be to alter to my preferred style. Instead of being an Automator workflow, this is actually a Python script and a few property lists. Great! Python is my favorite language. I copied the files to
~/Libary/PDF Services and edited them. The Python script is in a file named
tool. This script is well written, making it easy to modify. Here are the basic changes:
- Because I want to use timestamps, I added
import timeafter the other import statements.
- I changed the
destDirectoryto my preferred directory. The script already creates the destination directory if it doesn't exist, so altering the directory by date is easy, I added
destDirectory = os.path.join(destDirectory, time.strftime("%Y"))to automatically append the subdirectory for the year.
- The file uses the title of the webpage as the filename. To add the date as a prefix, add the line
title = "%s-%s" % (time.strftime( "%Y%m%d"), title)to the build path section. You can easily customize the date format.
- I prefer lowercase filenames, so I added
filename = filename.lower()to the
- If a file with this name already exists, the script appends a number to the name. I prefer different character than the default, so I changed it.
The final step was to I update the property list files so that the PDF menu shows the name I gave the command, instead of the original name from Apple.
I now have an even quicker way to save my receipts. Because the program is automatically generating the filenames using my preferences, I don’t have to change the name every time, and can avoid some typos and incorrect dates.