When I leave work I usually shut down my Mac before then turning off power to all devices via the switches on a pair of power strips. I've done it this way for many years and it's never been a problem as all external hard drives wind down when the Mac is powered off.
But now I have an external enclosure with several HDDs and SSDs in it (not a RAID) that works differently. The company that made it recommends manually ejecting all drives before shutting down the computer and turning off power.
Is it possible to write a macro that:
Properly unmounts all external drives except for the TimeMachine drive.
Shuts down the computer, but only if 1) has been successful
To unmount a drive called "External Drive 1" run the following command inside an Execute a Shell Script action with the following command.
diskutil unmount "External Drive 1"
Create an action like that for each of your other external drives. The default behaviours for the Execute a Shell Script action should suit your use case. Just change the third drop-down menu to read "ignore results" (so that you will not get any notifications unless an action fails).
Your macro's final action is of course Shut Down Computer.
The default settings for the shell script actions mean that if a drive cannot be unmounted, the macro will stop before the shutdown action can run.
try
tell application "Finder"
eject the disks
display notification "Successfully ejected all disks." with title "KM - Sleep Computer Macro" sound name "Frog"
end tell
on error
display dialog "Unable to eject all disks." buttons {"Close"} default button "Close"
end try