I’ve got a network-attached storage volume. It needs to be ejected prior to shut down or it risks corruption. I have to drag it manually to the trash to eject it before doing a shutdown or sleep.
Can AppleScript intercept the Sleep and Shut Down commands, eject the mounted volume, and then complete the Sleep / Shut Down?
Answer: Good point. For Shut Down, automatically log out all logged-in users. I’ve tried to get other users to log out when they are done, but that is hopeless. I just log them out when I shut down. If they lose work, tough luck. They’ve been warned.
As far as I know, there is no mechanism that allows Applescript to intercept standard OSX menu cmds.
So I do not see any solution other than circumvene the standard Sleep/Shut down commands (e.g. using Fruitmenu)
Rebuild the Apple menu and mimic Sleep/Shut down with a script that FIRST ejects any removable media as indicated and THEN sleeps or shuts down your CPU.