Auto-eject external drives when Macbook goes to sleep

Sep 15, 2009 · Follow on Twitter and Mastodon macos

Edit Aug. 28, 2010 - SleepWatcher has been changed and now differs from the information found below. This approach still works, though, as does the modified script.

After switching from PC to Mac, I’ve been annoyed to having to eject external disks before putting my computer to sleep.

Luckily, I found a workaround. The link below has a link to an app called SleepWatcher and provides you with a nice collection of wakeup and sleep scripts:

The script makes sure that any external disks are automatically ejected when the computer goes to sleep, which removes the need to do this manually.

However, while the original script will eject USB drives, mounted .dmg drives etc. as well, I have edited the sleep script to only eject a particular external drive.

osascript -e 'tell application "Finder" to eject (disks where name = "type in the name of your disk here")'

With this script, the specific disk will now eject when the computer goes to sleep. No more annoying warning messages about first ejecting the external drive.

Discussions & More

Please share any ideas, feedback or comments you may have in the Disqus section below, or by replying on Twitter or Mastodon.

If you found this text interesting, make sure to follow me on Twitter and Mastodon for more content like this, and to be notified when new content is published.

If you like & want to support my work, please consider sponsoring me on GitHub Sponsors.