So, I have an external HDD which is being used for Time Machine.
After getting to home, I usually connect my MacBook to a HDD via Hub and put it into sleep mode. Because I sometimes get back home late during the night, the Time Machine backup may happen during midnight. However, in the morning I have to wake up my mac, only to safely eject the HDD and put the MacBook into sleep mode again for bringing my MacBook out.
So I searched in order to create a scheduled disk eject job that can be run during sleep. I looked for solutions like crond
, launchd
, but even launchd
cannot run a script during sleep mode if I properly understood the documentation – even if I set up a job with StartCalendarInterval
it will not be invoked until the MacBook is woken up.
Is there any commercial app or another approaches that can be used for my situation?
My OSX is latest version of Mojave.
Best Answer
I think the Energy Saver suggestion is a good place to start:
» System Preferences » Energy Saver » Schedule and set it for, say, 30 minutes before you want to leave for work.
However, I would not schedule it to go back to sleep unless you know that it has actually succeeded in ejecting the disk. Otherwise you might have the disk not eject for some reason, and then if you remove the drive, you'll get that terrible message about ejecting a drive improperly.
So, let's say that you want to leave for work at 8:00 a.m.
Set Energy Saver to wake the computer at 7:30 a.m.
Then I would use Keyboard Maestro to run a script at 7:35 a.m. to unmount the drive. (You can schedule specific times for macros in Keyboard Maestro.)
The first step of the macro would be a shell script to unmount the drive.
I have a shell script to do this already, so I'm sharing it here. You can add a shell script as a step of a Keyboard Maestro macro.
All you'd need to do is change the
DRIVE="/Volumes/Time Machine"
line to reflect where your Time Machine drive mounts.The second step of the macro is a built-in feature in Keyboard Maestro to Put Computer To Sleep.
However, if the first step of the macro fails (i.e. if the drive does NOT eject) then the computer will not go back to sleep.