To unmount a named drive from the command line I wrote a bash function which just tells the Finder via AppleScript to eject the drive:

eject () { osascript -e "tell application \"Finder\" to eject disk \"$1\"" ; }

However I'd like to also find a way to subsequently re-mount that drive (by name), but this seems to be somewhat more complicated, perhaps requiring the use of diskutil ?

1 Answer 1


This code will work for non-encrypted drives:

mountall() {
    disks=$(diskutil list | grep "external, physical" | sed 's/ .*//')
    while IFS= read -r disk; do
        echo "Trying to mount disk $disk"
        diskutil mountDisk $disk
    done <<< "$disks"

For encrypted drives, you'd need to get the UUID of the drive by running diskutil coreStorage list and looking near Logical Volume Family for a the UUID of the drive that looks like ABCDEF-123456-GEHIJK-7890..., and then run:

diskutil coreStorage unlockVolume <UUID>

But this will prompt you for a password, which may be more troublesome than disconnecting and reconnecting the drive.

  • Thanks - I’ll give that a try!
    – Paul R
    Commented Apr 23, 2023 at 11:16
  • Sure, and if it does work, can you please accept the answer?
    – emonigma
    Commented Apr 24, 2023 at 11:36
  • It almost works, but (a) if seems to mount the EFI partition on each volume and (b) it doesn't mount a volume on a FAT32 SD card.
    – Paul R
    Commented Apr 25, 2023 at 13:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .