Switcing Locations and SMTP servers

Hi, I am new to both Applescript and this forum.
I’ve been looking for a way to automate the process of switching locations and switching the SMTP servers in Mail to correspond with the new location. So far I have been able to work out how to make a script that switches the SMTP server after I select my location from a dialog box (see script below), but I was wondering if there was a way to extend this to automatically switch my location in the Apple menu (or Network preferences) at the same time.

My next thing is to have this script activate every time I wake my Mac from sleep. Since I carry my Powerbook around a lot, I quite often put it to sleep to move between locations. It would be fantastic if my script would run everytime I open it up and wake it from sleep.

Can ANYONE help me with ANY of this??
Thanks :slight_smile:

My SMTP switching code: (first applescripting attempt :?)

try
set location_text to “Where are you?”
set location_query to display dialog location_text buttons {“Location1”, “Location2”, “Location3”} default button 2
set location to the button returned of location_query
set activate_query to display dialog “Welcome to " & location & “.” & " Click OK to activate the appropriate SMTP server settings.”
if the button returned of activate_query is “OK” then
if location is “Location1” then
tell application “Mail”
set smtp server of account “Account_Home” to ¬
smtp server “mail.domain1.net
set smtp server of account “Account_Work” to ¬
smtp server “mail.domain1.net
end tell
else if location is “Location2” then
tell application “Mail”
set smtp server of account “Account_Home” to ¬
smtp server “mail.domain2.net
set smtp server of account “Account_Work” to ¬
smtp server “mail.domain2.net
end tell
else if location is “Location3” then
tell application “Mail”
set smtp server of account “Account_Home” to ¬
smtp server “mail.domain3.net
set smtp server of account “Account_Work” to ¬
smtp server “mail.domain3.net
end tell
end if
end if
set confirmation to "Your settings have successfully been switched to " & location & “.”
set confirmation_ok to display dialog confirmation buttons {“Done.”}
on error
beep
set error_window to “None of your settings have been changed.”
set error_ok to display dialog error_window buttons {“OK”}
end try

Hi,

This works on my comp running Jaguar and using System Events beta:

tell application “Finder” to activate
tell application “System Events”
tell process “Finder”
tell menu bar 1
tell menu “Apple”
click
tell menu item “Location”
click
tell menu “Location”
tell menu item “MyTestLocation”
click
end tell
end tell
end tell
end tell
end tell
end tell
end tell

where “My TestLocation” is a location that was set up and shows in the Location menu of the Apple menu.

gl,

Thanks Kel, but it doesn’t seem to work with Panther. It keeps returning the error “System Events got an error: NSReceiverEvaluationScriptError: 4” after the command tell application “System Events” click menu “Apple” of menu bar 1 of process “Finder”

Cheers!

Does anyone have any other ideas???

A couple ideas for you, do you have a bluetooth phone/salling clicker? I can have an applescript run when i wake up from sleep because SC automatically connects to my phone and offers script run…

Another idea is to use http://www.ibeezz.com/en/ this software which can wake your computer up at any time and run a script…

dont know how helpful those tips may be…

Nick

Thanks Nick,

I actually already have all of those. My main issue with iBeezz is that you have to schedule the computer to wake for it to run a script. That isn’t quite what I was after. And the other issue with Salling Clicker is that I don’t want the script to run every time I move into the proximity zone - that would be mega annoying. Thanks heaps for your suggestions though - much appreciated.

Its just a bit frustrating when you know exactly what you want to do, but can’t find a way to do it.