Oct 06, '06 07:30:03AM • Contributed by: fredrikw
When I recently changed my workplace printers, I couldn't install the new printers in Classic. Since I print very seldom from Classic (but I do have one program that I have to use), I just used the Print to File option, and then printed the .ps file with Preview.app in OS X. Then I realised that I could simplify things with the help of a LaunchAgent and a QueueDirectory.
To achieve this, I started by making a small script that prints all files in a directory and removes them:
#!/bin/bash
# Script to be called by launchd that prints all files
# in the folder ~/classicprint/ and then deletes them
sleep 30
lp ~/classicprint/*
rm ~/classicprint/*
I saved the script as classicprint.sh, and put it in my home directory and made it executable with chmod a+x ~/classicprint.sh. I also made a new directory in my home drectory and called it classicprint.To make the LaunchAgent, I used Lingon by Peter Borg. Using the Assistant, I chose to "Run an application/script when something is added to a folder." I added a nice label in step two, and finally chose the classicprint.sh script as "Application/Script," and the folder classicprint as Watch Folder. The resulting plist-file looks like this.
If you don't use Lingon, paste that text into a text editor, change the ProgramArguments and QueueDirectories entries to match your system. Save in ~/Library/LaunchAgents with a suitable name ending in .plist. Then type this command in Terminal to load the agent:
launchctl load ~/Library/LaunchAgents/yourplist.plist
This could most certinely be solved with a Folder Action in the Finder as well, but this is how I did it. The sleep 30 command in the script is to give Classic time to finish printing. In my tests, it looked like the LaunchAgent was invoked as soon as the file was starting to be written to. This could also probably be fixed in a smarter way, but since I have more than a 30 second walk to the printer, this simple workaround does it for me.
