Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to change SMTP servers and Location Network
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.]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[11,365 views]  

A script to change SMTP servers and Location | 8 comments | Create New Account
Click here to return to the 'A script to change SMTP servers and Location' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to change SMTP servers and Location
Authored by: d. on Dec 23, '04 10:42:31AM
Or... use a script that asks where you are and then selects the correct SMTP server in Mail:

on run
set myResult to display dialog
"Where are you now?" buttons {"Office", "Home", "My Mother's Place"}
tell application "Mail"
if the button returned of myResult is "Office" then
set smtp server of account "Account1" to
smtp server "smtp.office.com"
set smtp server of account "Account2" to
smtp server "smtp.office.com"
else if the button returned of myResult is "Home" then
set smtp server of account "Account1" to
smtp server "smtp.home.com"
set smtp server of account "Account2" to
smtp server "smtp.home.com"
else
set smtp server of account "Account1" to
smtp server "smtp.mother.com"
set smtp server of account "Account2" to
smtp server "smtp.mother.com"
end if
end tell
end run

Put it in the Scripts Folder of Mail.app and select it via the Script Menu in Mail. Easily adjustable!

[ Reply to This | # ]
A script to change SMTP servers and Location
Authored by: fitzage on Dec 23, '04 12:28:29PM

I saw similar scripts, but I didn't want a multi-step process. I wanted to click once and be done to change all settings.



[ Reply to This | # ]
A script to change SMTP servers and Location
Authored by: cueball on Dec 24, '04 01:14:11PM
Why change SMTP servers at all? The original poster obviously is using a laptop - I do too. I take it everywhere - it goes with me whether I'm at work, home, my folks' place, conferences etc. From this post you would think that there's not an easier solution - but there is... postfix It's already on your machine. The instructions for enabling it have been posted numerous times on macosxhints. Just set your machine to enable outbound email only (do a search for "postfix" in the box above), set all your accounts to send using the localhost IP (127.0.0.1), then all you need ever do when you change physical location is select your new network location. AFAIAC, that's a one click solution, and you can have as many locations as you want without having to worry about modifying some script every time you need a new location.

[ Reply to This | # ]
A script to change SMTP servers and Location
Authored by: fitzage on Dec 24, '04 01:51:34PM

My ISP will not allow me to send anything out using my own, or any other smtp server. Many ISP's return my e-mails if they're not from a known smtp server.

If my ISP allowed that, I wouldn't need to do it. I'd just use .mac, etc's smtp servers at both locations.



[ Reply to This | # ]
A script to change SMTP servers and Location
Authored by: Ferdy on Dec 23, '04 11:01:22AM
Or use nbsmtp [ http://nbsmtp.ferdyx.org ] as i do (an develop)

Cheers, Ferdy

[ Reply to This | # ]
A script to change SMTP servers and Location
Authored by: the_webmaestro on Dec 23, '04 11:58:20AM
You can also use Andreas Amann's nifty MailScripts, which include a really nice interface for this and more (AddressBook stuff... the list is extensive!):
 
http://homepage.mac.com/aamann/

---
Father of Jeremy Logan

[ Reply to This | # ]

A script to change SMTP servers and Location
Authored by: fitzage on Dec 23, '04 12:31:38PM

I looked at those scripts, but as far as I can tell, it doesn't change the network location. Also, if I remember correctly, it gives a dialog box to change servers. I didn't want a dialog box. I wanted one click.

Yes, his scripts are nice, but they don't do what this one does.



[ Reply to This | # ]
A script to change SMTP servers and Location
Authored by: TimBonnici on Dec 23, '04 07:29:03PM

I use Location X to do this. It sits in the menu bar and reproduces the Location Manager functionality of OS 9 and then some. You can specify for each location the network settings, entourage and mail settings, time zone, quicktime settings, default printer, run applescripts and shell scripts. It's absolutely brilliant.



[ Reply to This | # ]