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"
reveal anchor "Network" of pane id ""
end tell

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

quit application "System Preferences"
end tell


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'"

Brad Reynolds said...

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

Jared 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...