How to mount / unmount external drives in Monterey?

Hi all,

I am able to unmount an external drive like this:

try
do shell script “diskutil unmount /Volumes/MyDrive/”
end try

  • but after unmount - the opposite (while still connected) does not work :

try
do shell script “diskutil mount /Volumes/MyDrive/”
end try

in terminal I get this error:
this says - Unable to find disk for /Volumes/MyDrive1/

How can I get the drive to mount again after unmount?:

Model: MacBook
AppleScript: 2.8
Browser: Safari 605.1.15
Operating System: macOS 12

Mounting the volume this way doesn’t work because the (unmounted) volume doesn’t exist at the given path.
You need the device node.

There is an expression which works since the first version of OS X

do shell script "diskutil mount `diskutil list | awk '/ MyDrive / {print $NF}'`"

Please note the different quotations »"«,»'« and »`«. The differences are crucial.

Thanks Very much for the info.

I have a very similar question. I made some typos when I posted last night.

What is the syntax for mounting a partition named Data 6 (with a space between Data and 6)? For example,

set myDirive to “Data 6”
do shell script “diskutil mount diskutil list | awk '/ MyDrive / {print $NF}'

gave a Script Error when I ran it. I just updated from Mojave to Big Sur. In Mojave, I had a similar script that mounted a group of external drives, but it no longer works in Big Sur. I based the above example using the suggestion here. If I could understand why this doesn’t work, I might be able to fix my longer script.

This cannot work because myDirive is not equal to MyDrive and apart from the (double) typo you are going to mount a volume with name MyDrive.

Try this instead

set myDrive to "Data 6"
do shell script "diskutil mount `diskutil list | awk '/ " & myDrive & " / {print $NF}'`"

Thanks, Stefan. I appreciate the reply.

I copied and pasted your two lines but I still get the script error:

Usage: diskutil mount [readOnly] [nobrowse] [-mountOptions Opt[,Opt]*]
[-mountPoint Path] DiskIdentifier|DeviceNode
Mount the volume in the “standard” place (/Volumes), unless an optional
“custom” mount point is specified.

In case this helps, from Terminal, I ran diskutil list and among my results are

4: Apple_HFS ⁨Data 6⁩ 1.0 TB disk4s4
and
6: APFS Volume ⁨Data 7⁩ 92.4 GB disk8s6

I tried your script with both Data 6 and Data 7 but received the same error message.

So… , now that I have run “diskutil list”, I tried your script again, but using “Apple_HFS Data 6” and then “APFS Volume Data 7”, and both worked!

This was NOT required in Mojave. Also, using the long names like “Apple_HFS ⁨Data 6” will make it much more complicated to modify my own script since that script also requires the short names. Is there not a way to mount just using the short names?

My bad, remove the space characters between the slashes and the double quotes

set myDrive to "Data 6"
do shell script "diskutil mount `diskutil list | awk '/" & myDrive & "/ {print $NF}'`"

Stefan,

I am getting used to a new keyboard so I know all about typing errors, as I initially made quite a few.

I tried the revised script and I got an interesting result.

First, I tried it as posted, with data 6, which does not have an APFS container. And… it worked! (hurray!)

Then I tried it with data 7, which is in an APFS container. And … I got the usual error message:

	--> e[b]rror[/b] "Usage:   diskutil mount [readOnly] [nobrowse] [-mountOptions Opt[,Opt]*]
     [-mountPoint Path] DiskIdentifier|DeviceNode

Then I tried it with two other partitions in that APFS container. Their names are MWF 7 and Parallels 7. Both worked!

I’ll try renaming and otherwise fooling around with Data 7 to identify the problem

I am using the script from this thread inside of a loop to mount disks. The disks are grabbed from a list. I have been using this script since, maybe, Mountain Lion, so nothing has changed since I upgraded my computer to Big Sur. But…

7 of the disks always successfully mount, 4 of them never mount (using the script).

I can find no attribute that distinguishes those that mount from those that don’t.

3 of the ones that don’t mount are APFS Sys volumes and the other is an APFS physical volume.

1 of the successesful ones is an APFS Sys volume, 4 are APFS physical volumes, and 2 are USB External volumes.

I also looked at “owners”, but some of the successful mounts have them enabled, others have them disabled. Same for the unsuccessful ones: some enabled, some disabled.

Is there anything else I can do to troubleshoot this?

Postscript. I just replaced the unsuccessful devices in the list with their device node names: disk6s3, disk6s2, disk6s1, and disk 9s4.

Three of these four now mount along with the others, but the 4th one, TTSS 8 = disk6s1, still won’t mount.

In Terminal, diskutil mount TTSS\ 8 also fails to mount

but, strangely, diskutil mount disk6s1 succeeds (but not the AppleScript version.)

Thanks for all this good info.