You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Script for encrypted thumb drive

Is there a way to mount an encrypted thumb drive just to the point of asking for password which I would enter, rather than going thru Disk Utility? Via AppleScript or Automator?


Running Monterey and Big Sur

iMac Line (2012 and Later)

Posted on Dec 21, 2021 8:15 PM

Reply
Question marked as Top-ranking reply

Posted on Dec 22, 2021 1:21 PM

Hi and thanks


It seems to work , but will this script work if dev disk changes? Not sure why disk 3s1 which happened to be the dev/disk for the thumb drive. Would incorporating the UUID somehow avoid the dev disk issue, unless your script takes care of that?



8 replies

Dec 22, 2021 9:34 AM in response to mrokloricred37

Conceptually this isn't hard. Disk Utility has a comprehensive command line interface you can invoke via do shell script.


However, the issue may be more identifying which disk you're trying to mount. diskutil usually uses internal deviceIDs, but these can vary - typically disks are assigned a number in the order they're attached, so today the drive might be disk3, but tomorrow it might be disk4.


That said, this script will prompt the user for a password, then pass that to diskutil to mount the volume:


-- prompt the user for a password
set thepw to text returned of (display dialog "What's the password?" default answer "" with hidden answer)
-- call diskutil
do shell script "diskutil apfs unlockVolume /dev/disk3s1 -passphrase " & thepw


Dec 23, 2021 10:16 AM in response to HWTech

works, tried a # of times where the dev disk changes:


I had tried this as a takeoff on Camelot's work and this worked...quite similar to yours


-- prompt the user for a password


set thepw to text returned of (display dialog "What's the password?" default answer "" with hidden answer)

do shell script "diskutil apfs unlockVolume [disk name] -user [uuid] -passphrase " & thepw


Thanks

Dec 23, 2021 1:18 PM in response to mrokloricred37

According to man diskutil, unlockVolume requires a 'volumeDevice' specifier, where:


An APFS Volume is identified by its device node, e.g. "disk5s1" or "/dev/disk5s1". The term

volumeDevice is used below to refer to this device node.


It doesn't say anywhere that a disk name or UUID can be used but, TBH, I didn't try anything else.


As I noted earlier, the issue with using diskxsy notation is that these change over time.

UUIDs should be static, so that would be preferable if it works.

disk name is asking for trouble - what happens if you have multiple attached disks that all have the same name - there is no expectation or requirement that disk names be unique.

Script for encrypted thumb drive

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.