Skip to content

Instantly share code, notes, and snippets.

@brunerd
Last active December 9, 2022 20:29
Show Gist options
  • Save brunerd/0e2aae5266ad518767bf9bbc6b24ae61 to your computer and use it in GitHub Desktop.
Save brunerd/0e2aae5266ad518767bf9bbc6b24ae61 to your computer and use it in GitHub Desktop.
Shell one liners for getting Mac hardware Serial, UUID, and Board ID
#Serial Number - x86/ARM
mySerial=$(/usr/libexec/PlistBuddy -c "print :0:IOPlatformSerialNumber" /dev/stdin <<< "$(ioreg -ard1 -c IOPlatformExpertDevice)")
#UUID - x86/ARM
myUUID=$(/usr/libexec/PlistBuddy -c "print :0:IOPlatformUUID" /dev/stdin <<< "$(ioreg -ard1 -c IOPlatformExpertDevice)")
#Provisioning UDID - ARM only, Monterey+ only
myProvisioningUDID=$(system_profiler -xml SPHardwareDataType | sed -e $'s/^[ \t]*//g;s/[ \t]*$//g' -e "s/date>/string>/g; s/data>/string>/g;s/real>/string>/g" | sed -e :a -e N -e '$!ba' -e 's/\n//g' | plutil -extract "0._items.0.provisioning_UDID" raw -o - -)
#Model ID - Universal
myModelID=$(sysctl -n hw.model)
#NOTE: Different output depending on platform!
# ARM (Device ID) - J314cAP
# Intel (Model ID)- MacBookPro14,3
#DeviceID - UNIVERSAL - uses xmllint --xpath
myDeviceID=$(ioreg -arc IOPlatformExpertDevice -d 1 | plutil -extract 0.IORegistryEntryName xml1 -o - - | xmllint --xpath '/plist/string/text()' - 2>/dev/null)
#DeviceID - macOS 12+ only, uses plutil raw output
myDeviceID=$(ioreg -arc IOPlatformExpertDevice -d 1 | plutil -extract 0.IORegistryEntryName raw -o - -)
#Board ID - Intel ONLY, Mac-551B86E5744E2388
#UNIVERSAL - uses xmllint --xpath
myBoardID=$(ioreg -arc IOPlatformExpertDevice -d 1 | plutil -extract 0.board-id xml1 -o - - | xmllint --xpath '/plist/data/text()' - | base64 -D)
#macOS 12+ only - uses plutil raw output
myBoardID=$(ioreg -arc IOPlatformExpertDevice -d 1 | plutil -extract 0.board-id raw -o - - | base64 -D)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment