Unmount external HDD when MBP on low battery

Any recommendations on automatically un-mounting external hard drives when my macbook pro is getting low on battery? There have been a couple of times when I forgot to plug in my MBP and had USB devices plugged in. When I get back to the my MBP, it says the drives were not disconnected properly. Are there any diagnostic tests I can run to make sure the drives are ok? Thanks in advance

MBP Late 2014
MacOS Mojave 10.14.6
External Hard drives - Seagate Backup + 8 TB

With the apps I have I’d create a KeyboardMaestro macro to look for a lowbattery property and activate some clicks on one of the many free or cheap disk eject/jettison menubar apps (I use Mountain). If you have KeyboardMaestro you might get some ideas on how to do this from these two links (or you might ask in the KeyboardMaestro discourse forum)

1 Like

I don’t know the easiest way to trigger it, but the easiest way to script the unmounting of a disk that I know of is

/usr/sbin/diskutil unmount Backup > /dev/null

(This is assuming your backup volume is named “Backup.”)

For years I’ve used this and a similar command to mount and unmount my backup drive before and after a SuperDuper backup.

(And now that I’ve looked at the diskutil man page for the first time in ages, it might be better to get rid of the > /dev/null and add the quiet option just before unmount.)

3 Likes

I do! Power Manager is the easiest way to make this work.

It’s an app designed to run certain actions (including scripts, AppleScripts, etc) when certain power “events” happen. For example, when my battery power gets to 30%, I get a persistent on-screen notification. At 20% the computer ejects drives and sleeps. At 10% it shuts down.

@bowline is correct that you can do this with Keyboard Maestro and/or launchd, but Power Manager is a great tool for stuff like this, in the same way that Hazel is better than Folder Actions.

The app used to be pretty expensive, but it’s now a $12/year subscription, I think, with a 30-day trial. Well worth checking it out.

1 Like

I use a script like this (and a related one) to mount and unmount my normal every-day volumes. I don’t have mine trigger automatically, I just launch them through LaunchBar. @r2d2 could then take that script and have it called by one of these other apps, like Keyboard Maestro. If the low power attribute wrote something to a file somewhere, you might be able to create a Hazel rule for it.

Some good ideas. I haven’t had a chance to work on it but I’ll update when I do. Thanks y’all