Mounting an Attached but Un-Mounted External Drive (Yes You Can!)

This may be obvious to others, but then again, it might not be.

Using the code I posted here:

... you can create a macro to mount an external drive that is connected to your computer, but isn't mounted.

I used to use an application called "Mountain" for this, but now I've rolled my own.



Thank you! Very useful.

1 Like

Different than how yours is set up, I've long mounted attached volumes with a scheduled AppleScript since I would rather specify the times when Time Machine is run.

    set theDisk to "Disk Name"
    do shell script "diskutil mount `diskutil list | awk '/ " & theDisk & " / {print $NF}'`"`

After Time Machine runs, another AppleScript unmounts the disk.

    set theDisk to "Disk Name"
    do shell script "diskutil unmount " & quoted form of ("/Volumes/" & theDisk)`
1 Like

I think they both amount to pretty-much the same thing. I also use them for Time Machine.

Hi there, I'm very new to KB Maestro. I just downloaded the submacros and read the yellow notes. Starting with "check if drive is mounted," where does the hard drive name go? Where it says cidmTriggerValue?

Read the instructions on the original post:

Thanks so much! Got it working.

KM is AWESOME. :smile:

1 Like

Is there a way to eject an SD card? It seems like they are handled differently. I cannot get the eject function to work on an SD card, and I notice a drive ejecting app I have also cannot manage SD cards.

Try this with your card name:

Thanks for the suggestion, but that didn't work. :slightly_frowning_face:

Rally? I've used that for years. What does the Keyboard Maestro error log say?

To clarify, $KMVAR_localCard is the name of your SD card as it appears in the Finder saved as localCard rather than the script reference ($KMVAR_localCard) to it.

I'm 99.9% the problem lies in my not understanding how to properly do what you're asking. :sweat_smile:

Here's what I did...please let me know what I"ve done wrong! :pray:

Change your Execute Shell Script script to:

diskutil quiet unmount "$KMVAR_udinDriveName"

Sadly that's not working either...Did I do what you said correctly? FWIW the log says that it failed with status 1.

I think there's a basic miscommunication here. In Finder, what is the name of the Flash drive when mounted?


It's an SD card and for the sake of dialing this process in, I have that SD card actually named SDCARD in finder. No spaces. All caps.

Just to be sure - have you got this setting on your shell script action?


Looks good (but looks can be deceiving). Here are a few tricks to try:

  • Use a Display Text action to display your card name variable surrounded by brackets to make sure there's no extraneous white space. Or just double check the Set Variable action. The name might not match what's in the Finder.

  • Run my command line with the actual SD card name in Terminal to confirm it works.

  • Run Disk Utiity to see if the card mounts and ejects there. We're using the command line equivalent.

I'm guessing it's a naming SNAFU.

@tiffle, yup, include all variables is checked.

I ran this in terminal "diskutil quiet unmount "SDCARD" and it did not work... :thinking: Gonna grab a few SD cards and see if it's something particular to this SDcard...

Update: there was in fact something strange happening with the SD card. I was unable to eject it by any means. MacOS claimed it was in use by another program. I logged out and logged into a user that had no running programs and still couldn't eject it. So I force ejected, logged out. Logged in. Eject started working normally for the card.

Logged back into my normal user and tested the KM settings basically as they were originally written and it worked this time. :sweat_smile: Thank you to everyone who was gracious enough to help me troubleshoot this. Some kind of weird hopefully one-off issue.

Interestingly, with testing it seems that if an SD card is called "Untitled" the unmount command doesn't work in terminal or KM. I'm guessing that's some kind of safety feature. If I change a card's name to Untitled1 the eject command in terminal and in KM work fine.

*The reason I was hoping to just go with "Untitled" is because I often format my SD cards in the cameras, and the default on every reformat is "Untitled," and I don't really want to rename them all the time. Although, as I type this, I bet I could have KM automatically rename an SD card with name "Untitled"...:thinking: