Thought I'd share my quick and simple bash script (with the help from Stokkes) for mounting AFP/SMB shares. Set your preferences, add the shares, and it will ping the server. If it is available then it will mount the shares. There is also an option to load iTunes at the same time.
Now works with Lion.
**NEW** Added functionality to wake the server via WOL **NEW**
28/12/2012 - Added the ability to call "wake" at the end of the script to wake the server, no matter which time it is. eg: /scripts/mount.sh wake
You must have wolcmd (included) in the same folder as the script. This is a definable directory. If the server is unavailable via ping, WAKE is set to TRUE, and the time is within the hours specified, then the script will attempt wake on lan. You must have your server MAC address and subnet in the options. This is all shown in the script.
Now if the server is unavailable it will exit iTunes. I found iTunes to be unstable if it can't resolve links to its music. You can set this in the script
Step 1: Where to put mount.sh & com.media.mount.plist
- Create a folder called "Scripts" on the root of your hard drive. This could be /Macintosh HD/Scripts.
- Copy mount.sh to this folder.
- Copy com.media.mount.plist to your user *Username*/Library/LaunchAgents folder. If the folder doesn't exist, create it.
Step 2: Editing the mount script
- Open mount.sh in text edit. Read the notes at the top of the script.
- Enter your username and password inside the quotation marks where shown. Read the notes in the file if your password has symbols (eg @, as you'll need to url encode them). Site is given in the script.
- Enter your server IP address (eg "192.168.0.100") and hostname (eg "tower") where shown. If your nas has a dynamic IP address (DHCP), enter the hostname instead of the IP Address.
- Leave Mount point alone, unless you want the shares to mount somewhere other than the default /Volumes
- Enter TRUE or FALSE if you want iTunes to open or not.
- Enter the protocol you want to use, either smb or afp.
- Enter the shares you want to mount. The shares must be space seperated (eg "TV Movies HD%20Movies". If the share name has a space in it, replace the space with %20 (eg "TV%20Shows").
Step 3: Enable script
- Double check the settings are correct, and make sure the mount.sh, and com.media.mount.plist files are in the correct place.
- Open Terminal (Applications/Utilities/Terminal). The sudo command will need your administrator password. Type:
- sudo chown root:staff /Scripts/mount.sh
- sudo chmod 775 /Scripts/mount.sh
- Restart your computer. It should mount your shares on login, and check if they're mounted every one minute.
If it's not working, double check permissions and settings. Try running the shell script by opening Terminal and typing:
- /Scripts/mount.sh
- Press enter
If that works, then check the status of the launchd agent by going into Terminal and typing
- launchctl list
- This will display the loaded launch daemons. If there is a 1 next to the com.media.mount.plist file, make sure the script is located on your boot volume, "/Scripts/mount.sh". If it's not in the list at all, make sure that the plist in your user Library folder, in a folder called "LaunchAgents".
Hope this is useful for someone!