Setting the default printer with a script with Mac OS X

After looking around the internet, I couldn’t find the answer in a single place, but I figured it out and so I might as well publish it here.

If what you want is to make a script so that all the user has to do is double-click something or run a script and their computer will use “XYZ PRINTER” default printer whenever they print, this is the sequence that works:

defaults write ~/Library/Preferences/org.cups.PrintingPrefs.plist UseLastPrinter -bool FALSE
lpoptions -d XYZ_PRINTER

The way it works is that line 1 turns off the “Use last printer” system preference that is the default setting. Then the second line actually sets the default printer. You’d think that all you need is the second line, but the “Use last printer” overrides it, so if you try doing just the second line nothing happens. It’s not obvious, unless you see it right in front of you like it is now 🙂

You can make this into an AppleScript pretty easily. Note that you have to replace any spaces in the name of the printer with an underscore.

Comments are closed.