How to Unmount an Exernal Drive using KM

I use TheBrain on an external drive because my MacBook Air’s internal drive is not large enough to hold all the attachments. Upon occasion, I have unplugged the drive before the program has completely Quit. I would like to make a macro that quits the program and then automatically unmounts the drive, but can’t seem to find a KM command that will unmount a drive. Is there one that I’m missing? Thanks.



tell application "Finder"
eject "BackupDrive"
end tell


Thanks! That hit the spot!!

This was easy, I just googled your question… Not being a smartass but we underuse google…
I’m happy I could help… :slight_smile:


Thanks Bill, I just searched the forum and came up with your post, I guess I could have googled to but I was searching for a Macro in Keyboard Maestro and thought the forum was a good place to search. Not being a smart-a just appreciative of your post. I AppleScript often but usually try to do it without AppleScript to see what Keyboard Maestro can do alone.

Unmount volumes using AppleScript

set volumes_ to {"vol 1", "vol2"} -- volume names
tell application "Finder"
   repeat with vol_ in volumes_
       eject disk vol_
   end repeat
end tell
1 Like

Not sure this will reach anyone seeing as it's a few years later, but... I've been using Mr. Mabey's macro and noticed something peculiar: the hotkey trigger (fn+ctrl+option+command+u) only works if I'm using my Bluebooth keyboard. If I do it with my MacBook keyboard, nothing. I remade the macro, using my MacBook keyboard, changed the trigger, etc. None worked with the MacBook keyboard. Thoughts?

@jsmith85 Keyboard Maestro distinguishes between external and internal keyboards. Simply add another Hot Key trigger—press the green plus-sign button and select Hot Key Trigger—and enter the same keyboard shortcut using the built-in MacBook keyboard. Once done, the trigger should work no matter which keyboard is in use.

Hmm, no luck. I added it, with the same trigger, using my MacBook keyboard (with my external keyboard turned off) and... nothing. When I try it on my external keyboard, a palette popped up asking which macro to use (since there were now two with the same hotkey trigger). The only thing I can think of is that my MacBook keyboard is somehow disabled for triggering macros, but other hotkey-based macros trigger when pressed.

This is not really true about hot keys. The system handles the hot key API, and for the most part it does not distinguish between keyboards. However, it is based on key codes, and they can vary between keyboards, although most of the keys have standard well defined key codes. Unusual keys may have different key codes on different keyboards.

Function keys on the MacBook keyboard should work either with the Fn key pressed or with it not pressed, depending on your system preferences. The Fn key is like a hardware toggle that toggles the single keyboard key between two different key codes.

If Keyboard Maestro is not getting the function key hot keys when he Fn key is in the appropriate state, then I would guess you have something low level actively blocking them on your Mac.

1 Like

Is there a way to mount the drive? I've googled a bunch and tried, to no avail:

  • Execute AppleScript
  • tell application "Finder"
  • activate
  • mount volume "VOLUME"
  • end tell

Hey @jsmith85,


os x (script OR command line OR Terminal) mount external drive

The simplest method is to use the label option in an Execute a Shell Script action:

mount Mercury

But you can complexify that if you want to.


I don't know if that's what you're looking for @jsmith85. Please enter your volume at the red arrow.

Global Disk Macros.kmmacros (52,0 KB)


1 Like

Thanks for the info, @ccstone. I had found that page but I'm definitely not well-versed enough to make much sense of it.

I ended up using @appleianer's macro - thanks a lot! Just curious - it works on my external hard drive but not a USB flash device. Is there a reason? I only wanted it for the external hard drive, so it's not a big deal. Thanks again.

Hey @jsmith85,

This is how it works.

Replace “Kannon” with your disk name.

I've pulled the disk name out of the shell script proper to make it simpler for you.

Multi-word disk names are fine too.

Mount Named Disk by Label copy.kmmacros (4.4 KB)

He's doing exactly what I'm doing except in a more roundabout fashion.

If you dismount a flash drive and then open the Disk Utility app, you won't see it in the list of available drives.

You have to physically unplug the drive and plug it back in, and as far as I know there's no way around this on macOS.

It's weird, because the system profiler can see it even after it's dismounted...


if you are looking for a very good tool to unmount/mount all Volumes and Flash Drives/SD cards @jsmith85, I can recommend the App Jettison.
It costs $5.95 per license/Mac and can be tested for 15 days.

In this video you can see an example with my USB stick "alexander" :wink:

1 Like

I know this is a very old thread, but it was mostly useful to me, but not did have the Shell method of unmounting:

diskutil unmount /Volumes/Freebird
(where "Freebird" is the name of the disk)

There, now it's there for someone else to find. :slight_smile:

1 Like

That works fine, as long as the name does not have any spaces or punctuation in it, but I would always recommend putting that in single quotes:

diskutil unmount '/Volumes/Freebird'

It won’t hurt anything if used when not needed, but getting in the habit of quoting paths when doing anything in shell will be a good habit to have.

(If you are using a variable such as $HOME then you need "double quotes" but that does not apply here.)