Sunday, July 15, 2007

Applescript to change Network Location

I have the need to change my network location from time to time. Opening the preference pane and making the change is tedious. Below is the applescript that I invoke from Quicksilver to change this. I'm still not sold on the language but being able to script the UI is fantastic.

tell application "System Events"
tell application "System Preferences"
activate
reveal anchor "Network" of pane id "com.apple.preference.network"
end tell

tell window "Network" of process "System Preferences"
tell pop up button 1
click
pick menu item "Home" of menu 1
end tell
delay 1
click button "Apply Now"
end tell

quit application "System Preferences"
end tell

4 comments:

FWT1 said...
This comment has been removed by the author.
FWT1 said...

easier way to do the same with applescript:

do shell script "scselect 'home'"

Unknown said...

Very nice. I had never heard of scselect before. That is much more elegant than my approach. :)

Unknown said...

I was doing something similar, until I remembered that there's a "Location" option in the Apple menu (accessed by clicking on the Apple icon in the top left of the screen).

Now, when I change locations, I just click the Apple, and set my location accordingly.

Of course, my next project is going to be figuring out how to automate connecting an SSH tunnel and setting the SOCKS proxy on my current location when using AirPort in questionable wifi settings...