Could you please help me figure out how to set up the following? I have a Thunderbolt enclosure with NVMe drives. I would like to prevent accidental ejections of this volume (for example, if I misclick and press cmd+E or press the ejection button on the sidebar of Finder) by having a warning message pop up, saying "Are you sure you want to eject this volume?". I want this macro to be triggered only for a specific volume called "Scratch".
At the moment, I figured out how to do the following:
However, this macro triggers action for all the volumes I eject and doesn't cover the part where I accidentally click the ejection button on the sidebar.
Instead of sending ⌘E at the end, send ⌃⌘E, which should only eject the selected volume.
Maybe someone brighter than me can figure this out, but I can't see a way you'll be able to do that with Keyboard Maestro—the OS is grabbing the mouse click event and acting on it.
You could write a macro that's activated on mouse click in a macro group that's active when Finder is frontmost, but what to do after that is complicated—I think you'd have to use a found image match in an if-then ... but this macro will run any time you click the mouse in Finder, and that might be an annoying experience, as there will be some tiny bit of lag every time.
Even with that said, I'm not sure it'd work—you have to catch mouse down, so the macro can take over before mouse up, when the OS is definitely going to eject the disk. Hopefully someone else can think of a creative way to handle this, but it seems really tough to me.
As @griffman's says, I don't think you can cover every "accidental" method -- and a macro that only sometimes warns you is, perhaps, worse than no warning at all!
But perhaps you could approach this from another direction? If you try and eject a volume from which you have files open, you'll get a warning. So have KM open a small text file in TextEdit or similar every time the "Scratch" volume is mounted -- you could then have an "Eject Scratch" macro that closed the file and ejected the volume when you did want to unmount it, eg as part of a sleep or shutdown routine.
Yeah, I think there is a more straightforward fix for the sidebar – I can just remove this drive from there.
My main question is: is it possible to make my macro work only with a "Scratch" drive and ignore others?
For example, if I highlight "Drive A" and "Drive B" and then press cmd+E, they would eject without the warning message.
If I highlight "Scratch," "Drive A," and "Drive B," then "Drive A" and "Drive B" will be ejected immediately, and a pop-up window will ask me if I am sure I want to eject the "Scratch" drive.
If you can select multiple drives, that implies you are in the top-level "Computer" Finder window. So you can use AppleScript to find out what's selected then eject or ask about each selected item as appropriate. Put this in a Group that is only active when the Finder is frontmost, just to be avoid ejecting drives when you don't want to!