A script to change SMTP servers and Location

Dec 23, '04 08:10:00AM

Contributed by: fitzage

I searched for hours using a variety of different phrases to try to find an AppleScript that didn't use GUI Scripting to change the network location in OS X. I couldn't find it, but I did finally find a tidbit in Apple's Developers documentation about scselect, which is a command-line application to change locations. I'm not sure if you need Developer Tools installed to use this or not, since I don't have a computer without them to test it on.

tell application "Mail"
  set smtp server of account "acctName" to smtp server "serverName"
end tell
tell application "Finder"
  do shell script "scselect locationName"
end tell
Replace acctName with the name of your account in Mail, change serverName to the name of your already-existing SMTP server in Mail. Replace locationName with the name of the Network location you want to switch to.

You can enter multiple lines of the line that begins with set smtp... for multiple accounts. I created two copies of this script and put them in the Scripts menu: one for work, and one for home (where I'm forced to use my ISP's smtp server). And yes, I know that the network location can be easily changed from the Apple menu. However, I wanted one step, not two.

[robg adds: We've run a few hints about various ways to use scselect.]

Comments (8)

Mac OS X Hints