Automatically set location based on connected SSID
Thu, Feb 23 2006 at 6:01AM PST • Contributed by: mirrorspock
Thu, Feb 23 2006 at 6:01AM PST • Contributed by: mirrorspock
I have a wireless network at home, and I also connect to several other networks at work. I do not use DHCP, so I have to manually select a network location each time I turn on my laptop. Using a few scripts I found here, I created this AppleScript that will automatically set the location based on the connected SSID.
It will also open shared drives, if they are defined in the script. If it doesn't find an SSID in the list, it will set the location to Automatic. With some extra work, it should be possible to also set the default printer.
I hope this is of some use to some people; I use it a few times each day in combination with SleepWatcher.
[robg adds: This previous hint does the same thing via a shell script, and this one works via bash and a launchd item.]
It will also open shared drives, if they are defined in the script. If it doesn't find an SSID in the list, it will set the location to Automatic. With some extra work, it should be possible to also set the default printer.
set AirportName to do shell script ¬
"system_profiler SPAirPortDataType|awk -F\": \" '/Current Wireless Network/{print $2}'"
tell application "Finder"
activate
end tell
set CurrentLocation to "Automatic"
if AirportName is "Home" then set CurrentLocation to "Home"
if AirportName is "Work1" then set CurrentLocation to "My work"
if AirportName is "Work2" then set CurrentLocation to "Other Office"
say "I think I am at location " & CurrentLocation & ", I will adjust my network settings accordingly"
tell application "System Events"
click menu item CurrentLocation of menu "Location" of menu item "Location" of menu "Apple" of menu bar 1 of process "Finder"
end tell
if AirportName is "Work1" then mount volume "smb://server/share"
if AirportName is "Home" then mount volume "smb://administrator@mycomputer/share"I hope this is of some use to some people; I use it a few times each day in combination with SleepWatcher.
[robg adds: This previous hint does the same thing via a shell script, and this one works via bash and a launchd item.]
•
[15,640 views]
