ID:276553
 
I spend all day with my laptop on various wireless networks--home, school, work. On each one are different file servers (FTP or SMB) that I need to work with. What I'd like to do is setup something to automatically mount different servers depending on what network I'm on.
It's not too terribly difficult to do by hand, but it's slightly annoying.
I've tried using automator, and I've looked at launchd, but don't seem to be able to find any way to conditionally act upon the network name at connection time.
Thus far OS X has been capable of doing all the weird stuff I want it to do, so I'll be dissapointed if this isn't possible :-)
Anyone know of any way to do it?
nick.cash wrote:
I've tried using automator, and I've looked at launchd, but don't seem to be able to find any way to conditionally act upon the network name at connection time.

Haven't tried this myself, but my suggestion would be to make it just slightly manual, by creating an automator script (or whatever form of automation you decide to use) for each of the network setups you want, and run it to be set your Location to that network and mount what you want.

This would be pretty much the same experience as using the Apple menu to change your Location.

There may be a better way...I will ask around.
In response to Deadron
if MacOS X still uses AppleScript (or whatever modern variant they currently support), you could - in principal - write up a mounting script to your tastes, and attach that to an icon or dock-applet that you can click on.
I don't know anything about Automator, and I'm not sure if something can be done automatically when a network is first connected. Quite frankly, even in Tiger, OS X leaves a lot to be desired in how seamlessly it can connect or disconnect from network servers when a laptop changes environments.

That said, I have a handy little AppleScript that I use at work to connect my servers in one shot. Basically, for each server, I have a block of code like this:

try
tell application "Finder"
mount volume "smb://domain;username@server/sharename"
end tell
end try


Domain and username are optional, but that'll fill in the right values when the dialog pops up for your password. You can of course have Keychain remember the password so that future attempts occur automatically.

You'll create the script in Script Editor and save it as an Application with options "Run Only". Then you have a double-clickable app that you can have on the desktop, dock, etc. for easy access. I have mine in Startup Items, but that doesn't help much when frequently changing networks.
nick.cash wrote:
I spend all day with my laptop on various wireless networks--home, school, work. On each one are different file servers (FTP or SMB) that I need to work with. What I'd like to do is setup something to automatically mount different servers depending on what network I'm on.

Here is some advice I got in asking about this:

--------------
This is the command I used when I had to give my laptop a static IP at home (but could use DHCP at work):

system_profiler SPAirPortDataType | grep "Current Wireless Network" | sed s/".*Current Wireless Network:\ "//g

That's all one line. My script detected my home network or 42Net at work and set its network configuration accordingly. Your friend's script would have to use mount_ftp and mount_smbfs to do the rest. I dunno if there's a more efficient way to find the BSID, but this worked with no flaws for me. My script was run using SleepWatcher from this guy's site:

http://www.bernhard-baehr.de/

because I would always wake from sleep to a new network connection.