Help Unmouting disk if UUID is mounted until a Specific Time Every morning I have the same routine.  

I come into work and plug in my peripherals including my Time Machine Backup. I have my Time Machine scheduled to only run one daily backup at 3:30pm.  I would like to run a script or a .plist LaunchDeamon to check all inserted external hard drives automatically and unmount if the

UUID = 32E89C07-FFDB-36F3-8CE8-5DC0560AFEC4  


And then mount it at 3:15pm.  I just do not want my drive to be plugged in all day just to use it for 30 mins to back everything up. 

I know this could all be resolved if I just manually plug in the drive at 3:15. However, some days I am in a meeting or away from the desk and what-not. 

I was able to find documentation on how to auto eject the device at a specific time so I do not have to remember to safely remove the drive.

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
    &lt;dict&gt;
        &lt;key&gt;Label&lt;/key&gt;
            &lt;string&gt;com.diskejector.Backup&lt;/string&gt;
        &lt;key&gt;ProgramArguments&lt;/key&gt;
        &lt;array&gt;
            &lt;string&gt;/usr/sbin/diskutil&lt;/string&gt;
            &lt;string&gt;unmountDisk&lt;/string&gt;
            &lt;string&gt;32E89C07-FFDB-36F3-8CE8-5DC0560AFEC4&lt;/string&gt;
        &lt;/array&gt;
        &lt;key&gt;StartCalendarInterval&lt;/key&gt;
        &lt;dict&gt;
            &lt;key&gt;Hour&lt;/key&gt;
                &lt;integer&gt;16&lt;/integer&gt;
            &lt;key&gt;Minute&lt;/key&gt;
            &lt;integer&gt;45&lt;/integer&gt;
        &lt;/dict&gt;
    &lt;/dict&gt;
&lt;/plist&gt;


I would like some help with auto launching a .sh script that could also include the previous code I have to eject the drive at the end of the day.
There is no shell script needed if you use two launch agents.

You need the UUID of your Time Machine backup drive:

diskutil info $VolumeName | grep "Disk / Partition UUID:"


Replace $VolumeName by the actual volume name of your TM drive. If the name contains spaces use double quotes (e.g. "Time Machine backup drive".

Create two files usr.tmvolume.unmount.plist and usr.tmvolume.mount.plist in ~/Library/LaunchAgents/:

nano ~/Library/LaunchAgents/usr.tmvolume.mount.plist


with the content

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;usr.tmvolume.mount&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;/usr/sbin/diskutil&lt;/string&gt;
        &lt;string&gt;mount&lt;/string&gt;
        &lt;string&gt;$UUID&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;StartCalendarInterval&lt;/key&gt;
    &lt;array&gt;
        &lt;dict&gt;
            &lt;key&gt;Hour&lt;/key&gt;
            &lt;integer&gt;15&lt;/integer&gt;
            &lt;key&gt;Minute&lt;/key&gt;
            &lt;integer&gt;15&lt;/integer&gt;
        &lt;/dict&gt;
    &lt;/array&gt;
&lt;/dict&gt;
&lt;/plist&gt;


and

nano ~/Library/LaunchAgents/usr.tmvolume.unmount.plist


with the content:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;usr.tmvolume.unmount&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;/usr/sbin/diskutil&lt;/string&gt;
        &lt;string&gt;unmount&lt;/string&gt;
        &lt;string&gt;$UUID&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;StartCalendarInterval&lt;/key&gt;
    &lt;array&gt;
        &lt;dict&gt;
            &lt;key&gt;Hour&lt;/key&gt;
            &lt;integer&gt;8&lt;/integer&gt;
            &lt;key&gt;Minute&lt;/key&gt;
            &lt;integer&gt;30&lt;/integer&gt;
        &lt;/dict&gt;
        &lt;dict&gt;
            &lt;key&gt;Hour&lt;/key&gt;
            &lt;integer&gt;15&lt;/integer&gt;
            &lt;key&gt;Minute&lt;/key&gt;
            &lt;integer&gt;45&lt;/integer&gt;
        &lt;/dict&gt;
    &lt;/array&gt;
&lt;/dict&gt;
&lt;/plist&gt;


Replace $UUID in both plists by the UUID of your Time Machine volume found previously.

Load both plists with:

launchctl load ~/Library/LaunchAgents/usr.tmvolume.*


Now the TM backup  drive will be unmounted at 8:30am, mounted at 3:15pm and unmounted again at 3:45pm. Adjust the dates as needed.