I've been getting more and more into using launchd to automate everything on my home server, and I'd like to harness some of it's power on my client machines. I basically want to figure out how to keep my server's AFP share mounted at all times. The only real issue I see myself running into is the script banging itself into a wall when I'm on a network that has AFP blocked. I'd think do something like try 3 times then give up, but then I'd have to restart the script when I left the network. I'm not quite sure how to write an if construct within the plist to make sure it can connect, or to check to see if the volume is already mounted. The only scripts I've written so far are to keep OS X applications alive.
Asked
Active
Viewed 1,230 times
1 Answers
0
Take a look at LocationChanter. The plist item it uses is:
<key>WatchPaths</key>
<array>
<string>/Library/Preferences/SystemConfiguration</string>
</array>
From what I can tell, the files in that directory are updated each time your network changes. So that would give you your first trigger. The other plist item to look at is "PathState". The launchd.plist man page has the following documentation for it:
PathState <dictionary of booleans>
Each key in this dictionary is a file-system path. If the value of
the key is true, then the job will be kept alive as long as the
path exists. If false, the job will be kept alive in the inverse
condition. The intent of this feature is that two or more jobs may
create semaphores in the file-system namespace.
I'm just getting into launchd myself, but I think you can use that in combination with the WatchPaths to setup what you're looking for. The idea being to watch for the mounted drive and if it's not there attempt to mount it.
Of course, you probably want some throttle on this. Especially if the client machine will ever connect to other networks, but I think those elements should get you started.

Alan W. Smith
- 24,647
- 4
- 70
- 96