I recently needed to switch printers using scripting in FileMaker Pro 7. FileMaker (FM) officially supports the feature, but it is buggy and will often not work (the bug is documented by FileMaker). So before printing using a FM scriptt, I wanted to change the default printer. And AppleScript only supports that using UI scripting. I figured Cups/GIMP would have the feature as well, but in a Terminal command. The commands I used to figure this all out are documented on the Cups/GIMP webpages -- you can even check ink reserves in inkjet printers using terminal! Here's how to do it all.
- lpstat gives you status of printer queues and the names.
- lpoptions allows printer settings to be changed for the current user.
- lpadmin allows the settings to be changed for all users, but I couldn't get that to work (user settings override, I guess).
Do
lpstat -a in the Terminal, and it returns:
$ lpstat -a
HP_LaserJet_4100_MFP__0001E66197AF_ accepting requests since Jan 01 00:00
HP_LaserJet_4100_Series__000E7FDE2702_ accepting requests since Jan 01 00:00
Two Laserjets, the printer name is actually the queue name. To change the default printer to the MFP machine, for instance, do this:
lpoptions -d HP_LaserJet_4100_MFP__0001E66197AF_
FileMaker can do this via an Applescript:
do shell script ("lpoptions -d HP_LaserJet_4100_MFP__0001E66197AF_")
I put the above snippet right at the beginning of the FileMaker script ... and it works like a charm! Fast, clean, and mean. And no UI Scripting. This is invisible.