network printer swap

I want to make an app that will switch my default printer under the “Printer & Fax” preference Pane in System Preferences based off of the network I am on. I want to be able to have it do that automatically.

Please reply ASAP!


printer setup utility is an application, so you may be able to script that to set the default printer. You may be able to search the forums on that.


try this

set {connected, wired, IPAddress, ssid} to getLocation()

if connected then
	if wired and IPAddress is "" then
		do shell script "lpoptions -d myPrinter1"
	else if not wired and ssid is "myWLAN" then
		do shell script "lpoptions -d myPrinter2"
	end if
end if

on getLocation()
	set wiredIP to do shell script "/sbin/ifconfig en0 | /usr/bin/awk '/inet / {print $2}'"
	if wiredIP is not "" then
		return {true, true, wiredIP, ""}
		set wirelessIP to do shell script "/sbin/ifconfig en1 | /usr/bin/awk '/inet / {print $2}'"
		if wirelessIP is not "" then
			set ssid to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | /usr/bin/awk '/ SSID: / {print $2}'"
			return {true, false, wirelessIP, ssid}
			return {false, false, "", ""}
		end if
	end if
end getLocation

getLocation() returns the following parameters
wired (boolean) : ethernet or airport
connected (boolean) : connected to a network
IPAddress (string) : the local IP address
ssid (string) : the name of the wireless base station (if wired is false)

the shell command lpoptions -d sets the printer.
Consider that the names of the printers have a special format.
You can get a list of available printers with

set UNIX_Printers to paragraphs of (do shell script "lpstat -a")

Im looking for it to do this when i switch wireless networks.


how do I make a display dialog function show up to tell me “The default printer has successfully been changed to [PRINTER NAME HERE]!” Where the “[PRINTER NAME HERE]” is where the printer’s name will go without the quotes or brackets.