Wednesday, January 19, 2022

#1 2022-01-06 10:26:43 am

davemac
Member
Registered: 2008-03-10
Posts: 8

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


Filed under: mount, unmount

Offline

 

#2 2022-01-06 10:45:27 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11763
Website

Re: How to mount / unmount external drives in Monterey?

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

Applescript:

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

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

Last edited by StefanK (2022-01-06 10:46:22 am)


regards

Stefan

Offline

 

#3 2022-01-09 01:01:20 pm

davemac
Member
Registered: 2008-03-10
Posts: 8

Re: How to mount / unmount external drives in Monterey?

Thanks Very much for the info.

Offline

 

#4 2022-01-09 09:34:09 pm

budsimrin
Member
Registered: 2008-10-16
Posts: 4

Re: How to mount / unmount external drives in Monterey?

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.

Last edited by budsimrin (2022-01-10 04:31:02 pm)

Offline

 

#5 2022-01-11 02:02:41 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11763
Website

Re: How to mount / unmount external drives in Monterey?

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

Applescript:

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


regards

Stefan

Offline

 

#6 2022-01-11 04:06:22 pm

budsimrin
Member
Registered: 2008-10-16
Posts: 4

Re: How to mount / unmount external drives in Monterey?

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?

Last edited by budsimrin (2022-01-11 05:44:50 pm)

Offline

 

#7 2022-01-14 02:31:23 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11763
Website

Re: How to mount / unmount external drives in Monterey?

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

Applescript:

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


regards

Stefan

Offline

 

#8 2022-01-14 11:02:27 am

budsimrin
Member
Registered: 2008-10-16
Posts: 4

Re: How to mount / unmount external drives in Monterey?

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:

        --> error "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

Last edited by budsimrin (2022-01-14 11:09:27 am)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)