Script to change location in system preferences

Hi there,

Because I use my ibook both at work and at home, I had two network settings setup (locations); 1 is called home and 1 is called work.

Everytime I login at work or home, I will need to goto system preferences to change the location to work or home.

Is there a script that I can write to change the location automatically… and I can put the respective script as a login item so that the location can be changed automatically.

I had looked into the dictionary but cannot find anything regarding change of location.

Any help is appreciated. Thanks in advance.

Cheers

Winston

You should be able to switch locations simply by using the ‘Apple’ pull down menu and go to ‘Locations’.

If you don’t find a way to script it, this might help. It is a direct quote from Apple’s help system (OS X 10.2.6).

“After you create your locations, you can switch all of your network settings by choosing a location from the Apple menu.”

Hi there,

Thanks for the reply…

Changing location from the apple menu was what i had been doing throughout.

However, there are occasions, esp in the MORNING, when I got in work half awake, i login work account and go into Microsoft Outlook right away (which is running under classic) and TOTAL FORGOT to change location.

This is annoying as my outlook will fail with the worng location selected…
so I need to quit it, change location, relaunch classic, took 3 mins and back to operation.

Well… is there a way to script apple menu to automate this task??

Thanks heaps heaps!!

Cheers

Winston

:shock: You threw me off in your original post with “Everytime I login at work or home, I will need to goto system preferences to change the location to work or home.” :wink:

If you are running OS X 10.2.3 or later, you might be able to use GUI Scripting.

Sorry Rob… didn;t mean to do that…

I was using system perferences for around 3 months until I discover ther apple menu part by accident couple of weeks ago…

Anyway… Thanks for the suggestion, I will have a look at GUi scripting now…

Sorry!!!

Cheers

Winston

Hey Winston, no harm was done and no apologies are necessary. Good luck!! :slight_smile:

Hi there,

I had found this important info from GUI regarding changing network location:

Below is the script:

tell application “Finder”
activate
end tell
tell application “System Events”
get properties
get every process
tell process “Finder”
get every menu bar
tell menu bar 1
get every menu
tell menu “Apple”
get every menu item
tell menu item “Location”
get every menu
tell menu “Location”
get every menu item
get properties of every menu item
click menu item “Automatic”
end tell
end tell
end tell
end tell
end tell
end tell

Okei… this script makes sense to me… I sort of know what it is trying to do…
The script CAN PASS CHECK SYNTAX, but got an error when excute…
Here is the error message at “Tell menu bar 1, get every menu”

Execution error:
System Events got an error
NSReceiverEvaluationScriptError: 4

I have no idea what this this…
Can anyone please help me…

Deeply Appreciated.
Thanks

Winston

One thing that’s easy to miss when first installing GUI scripting is a setting in the Universal Access pref pane. You need to turn on “Enable access for assistive devices”. Have you done this?