Location Based Auto-Setting of Default Printer via Keyboard Maestro

I was looking for a way to automatically set the default printer based on the location I am at (office/home), however I could not find a way to do it natively using system preferences. I ended up using a Keyboard Maestro macro that is triggered via the WIFI SSID. I’m sharing as I think it’s useful and free (if you already own KM).

You will need first to get the system names of your printers, you can do that using the Terminal command “lpstat -p”

Once done, you can use the KBM Macro below:

The AppleScript is: do shell script (“lpoptions -d EXAMPLE_PRINTER_NAME”)

Of course you will have to change the EXAMPLE_SSID to the name of the WiFi network you want to use to trigger the macro, and the EXAMPLE_PRINTER_NAME to the printer name after running “lpstat -p” on Terminal. You will need to create a separate macro in Keyboard Maestro for each location/WIFI network name trigger.

I hope you find this useful. If you know and easier way to do it please share. And as always, GO GREEN, only print if you really need to!

6 Likes

I am always amazed by all the triggers Keyboard Maestro has. Thanks for sharing this :smile:!

1 Like

Glad you found it helpful!

Very nice! I like the %ExecutingMacro% in the title of the notification. Going to steal that one from you :wink:

A small piece of advice (that might nog even impact this macro, since the output of lpstat -p seems to convert spaces to underscores anyway): if you want to execute shell scripts in Keyboard Maestro, you can just use the “Execute Shell Script”-action.

This has a couple of advantages, the main one being it might be easier with escaping. Let’s say your printer name is “My Awesome Printer”. You might need to wrap that in double quotes.

In the AppleScript you’d have to write:

do shell script("lpoptions -d \"My Awesome Printer\"")

(Notice the extra \)

In “direct shell script” you can just write:

lpoptions -d "My Awesome Printer"

It’s a small thing, but it might prevent you searching for a bug in the future when things “sometimes don’t work”. :slight_smile:

2 Likes