Can't unmount password-protected partition [SOLVED]

I have a password-protected partition called "MyDisk".
I'm trying to unmount it, but this does not work in Keyboard Maestro:

#!/bin/bash

VOLUME_PATH="$KMVAR_Local__volumeDiskName"

diskutil eject "$VOLUME_PATH" 2>/dev/null

while mount | grep -q "$VOLUME_PATH"; do
  sleep 5
done

osascript -e 'display notification "'"$VOLUME_PATH"'" with title "✅ Unmounted Successfully!"'

while this works in Terminal:

diskutil eject /Volumes/MyDisk

Any tips on what's happening?
I have a similar script for external disks and they work (not password-protected).

Try diskutil unmount "MyDisk".

That would be the most reliable method, in my experience.

1 Like

Thank you.
I actually tried something like that just now (suggested by ChatGPT) and it worked.

So, the final script is now:

#!/bin/bash

VOLUME_PATH="$KMVAR_Local__volumeDiskName"

diskutil unmount force "$VOLUME_PATH"

while mount | grep -q "$VOLUME_PATH"; do
  sleep 5
done

osascript -e 'display notification "'"$VOLUME_PATH"'" with title "✅ Unmounted Successfully!"'

Would it be ok to leave force? Or just diskutil unmount "MyDisk"?
This disk is kind of a "backup" and I will usually just run this macro once I have all files safe somewhere else.

1 Like

The manual page for diskutil notes (unsurprisingly) that the force option is “less kind to any open files”, so why not see how you get on without that option. I do not think you will need it.

1 Like

Thank you for clarifying, Kevin.

1 Like

Hi, @alltiagocom. On a related note, you might find this macro useful: