Scheduled unmount disk(s) (macOS)

How to unmount (eject) disk(s) from macOS on schedule without using Automator or any other external app or scripter.

*The content was originally found on reddit, written by /u/neuralspark –shamelessly pasted here to serve as personal archive :-)

Make a new text file named com.diskejector.YOUR_VOLUME_HERE.plist on your desktop. Open it, and paste this into it. The Hour value is a 24 hour format, so this would eject all volumes on the disk that has the drive named YOUR_VOLUME_HERE on it at 6 PM everyday. Obviously change the YOUR_VOLUME_HERE and the 18 to meet your requirements.

[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.diskejector.YOUR_VOLUME_HERE</string>
<key>ProgramArguments</key>
<array>
<string>/usr/sbin/diskutil</string>
<string>unmountDisk</string>
<string>YOUR_VOLUME_HERE</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>18</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</dict>
</plist>
[/code]
Save and close it

Open Terminal, and type the following lines:

sudo mv ~/Desktop/com.diskejector.YOUR_VOLUME_HERE.plist /Library/LaunchDaemons/

sudo chown root:wheel /Library/LaunchDaemons/com.diskejector.YOUR_VOLUME_HERE.plist

sudo chmod 644 /Library/LaunchDaemons/com.diskejector.YOUR_VOLUME_HERE.plist

sudo launchctl load -w /Library/LaunchDaemons/com.diskejector.YOUR_VOLUME_HERE.plist

Boom! Now your disk will unmount each night at 6 PM. It will fail silently if the disk isn’t there, so no harm no foul.

Repeat this for each volume you need to unmount, replacing YOUR_VOLUME_HERE with the drive name.

Leave a Reply

Your email address will not be published. Required fields are marked *