Alternative way to do it with diskutil. Below I have used a place holder, "VOLUME NAME" which you will need to edit with your volume name.
Schedule mounting at 13:00.
Copy and save the following as:
com.yourname.timed_mounting.plist in
~/Library/LaunchAgents/.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.yourname.timed_mounting</string>
<key>ProgramArguments</key>
<array>
<string>diskutil</string>
<string>mount</string>
<string>VOLUME NAME</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>13</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</dict>
</plist>
Schedule unmounting at 14:00
Copy and save the following as:
com.yourname.timed_unmounting.plist in
~/Library/LaunchAgents/.
Code:
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.yourname.timed_unmounting</string>
<key>ProgramArguments</key>
<array>
<string>diskutil</string>
<string>unmount</string>
<string>VOLUME NAME</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>14</integer>
<key>Minute</key>
<integer>0</integer> </dict>
</dict>
</plist>
Now, everything should be done. Log out and log in again and you have your scheduled mount/unmount in place. One thing to remember though, if you eject the drive from Finder it will both unmount and detatch it. For this to work your USB key needs to be attached, so if you want to unmount it manually, do:
diskutil unmount "VOLUME NAME" in Terminal or diskutil will not find the drive.
But, in addition you actually need a 3rd Plist file to automatically unmount the disk every time you log in since OS X will mount it automatically. If you happen to log in between 1 and 2 am though, well you'll need to write a script that checks if this is the case an only perform the unmounting if that isn't the case.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.yourname.unmount_at_load</string>
<key>ProgramArguments</key>
<array>
<string>~/Scripts/unmount_maybe.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
The script needs to be placed in a folder called ~/Scripts which is in the root of your home directory and be called unmount_maybe.sh.
Code:
#!/bin/bash
VOLUME_NAME="VOLUME NAME"
TIME=$(date "+%H")
if [ "$TIME" -lt 13 ] || [ "$TIME" -ge 14 ]
then
diskutil unmount "$VOLUME_NAME"
fi
You need to make this script executable with: chmod +x unmount_maybe.sh
And you're done.