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