Skip to content

Instantly share code, notes, and snippets.

@jj1bdx
Created July 23, 2019 04:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jj1bdx/71448a1b02a8b02f0b56ea031a588d03 to your computer and use it in GitHub Desktop.
Save jj1bdx/71448a1b02a8b02f0b56ea031a588d03 to your computer and use it in GitHub Desktop.
Using macOS diskutil output to search the device identifier for a given volume name
#!/bin/sh
# search mount point based on the device name
search_devicename () {
diskutil list -plist | \
plutil -convert json -r -o - - | \
jq -c '[.AllDisksAndPartitions[].APFSVolumes, .AllDisksAndPartitions[].Partitions] | flatten | map(select(has("VolumeName")))[] | {volume: .VolumeName?, id: .DeviceIdentifier?}' | \
jq -r --arg volname "$1" 'select(.volume == $volname) | .id?'
}
# mount an external disk with "external_disk_name"
diskutil mount `search_devicename external_disk_name`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment