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.
## Change this to wherever your Time Machine drive mounts
## Change this to however many times you want to try before
## the script considers itself to have failed.
## Only change this if you know you need to
## initialize the counter. Don't change this :-)
## This `while` loop will keep going until the drive no longer appears at the mount
## point, or we exceed the number of attempts we defined above.
while [[ -d "$DRIVE" ]]
# increment counter
# check to see if we have exceeded maximum attempts
if [ "$COUNT" -gt "$MAX_ATTEMPTS" ]
echo "Exceeded '$MAX_ATTEMPTS' trying to eject '$DRIVE'."
## This will cause the script to fail
## which should cause the Keyboard Maestro macro to fail
## so it won't go to sleep, so you'll know that you
## have to manually eject the drive
# don't sleep the first time through the loop
[[ "$COUNT" != "1" ]] && sleep 10
# This is where we try to eject the drive
diskutil eject "$DRIVE"
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.