Skip to main content

Report the Full Mac Model Name with a Custom Field

What the Custom Field returns

This macOS Custom Field returns a readable model name, such as MacBook Pro (Retina, 15-inch, Mid 2015), instead of only a model identifier such as MacBookPro11,4. Use the value in inventory reports and Smart Groups where a human-readable hardware model is useful.

If necessary, please view the following for details on creating Custom Fields.

How the lookup works

The script first checks model information stored locally by macOS. If that lookup does not return a name, it tries additional local hardware data and then the older Apple serial-number lookup for compatible serial formats. If no readable name is found, it returns the hardware model identifier rather than leaving the Custom Field blank.

Local macOS wording can differ from Apple's older lookup response even when both identify the same model. The examples below show why reports should not compare the display strings as exact canonical names:

Examples:

   
Name as indicated by Apple's servers and About This Mac Name as stored in local file
MacBook Pro (13-inch, M1, 2020) MacBook Pro (13-inch, M1, 2020)
MacBook Pro (Retina, 15-inch, Mid 2015) 15" MacBook Pro with Retina display (Mid 2015)
iMac (21.5-inch, Late 2009) iMac Intel Core 2 Duo (widescreen, Late 2009)
Mac mini (Late 2012) Mac mini (Late 2012)

Virtual devices

Virtual machines may not have a valid Apple serial number. The script detects VMware model identifiers and returns that identifier directly. If you adapt it for Parallels, VirtualBox, or another hypervisor, preserve a deterministic fallback value and test it separately from physical Macs.

Custom Field script

Create a macOS client script Custom Field with the code below. Pilot it on Apple silicon, Intel, and virtual Macs represented in your fleet. Treat the readable name as reporting metadata; keep the hardware model identifier available for exact technical targeting.

#!/bin/zsh
  
mac_model=$(sysctl -n hw.model)
  
if [[ "$mac_model" =~ ^"VMware" ]]
then
        echo "$mac_model"
        exit 0
fi
  
# File that stores device information.  Old models may not have this file.  Additionally some models only have a description
# Information is not exactly the same as that reported through About This Mac, but is similar enough to suffice in most instances
apple_locale=$(defaults read /Library/Preferences/.GlobalPreferences.plist AppleLocale)
attr_file="/System/Library/PrivateFrameworks/ServerInformation.framework/Versions/A/Resources/${apple_locale}.lproj/SIMachineAttributes.plist"
  
if [ -e "$attr_file" ]
then
 
    # Use marketingModel if available
        model_name=$(/usr/libexec/PlistBuddy -c "Print :${mac_model}:_LOCALIZABLE_:marketingModel" "$attr_file" 2>/dev/null)

    # If not found, use description if available
        if [ -z $model_name ]
        then
                model_name=$(/usr/libexec/PlistBuddy -c "Print :${mac_model}:_LOCALIZABLE_:description" "$attr_file" 2>/dev/null)
        fi
fi

# If not found in plist check ioreg.  Apple seemed to have stopped populating the plist file, but do populate ioreg data now
if [ -z "$model_name" ]
then        
    model_name=$(ioreg -c IOPlatformDevice | awk -F "\"" '/product-name/ || /product-description/ {print $(NF-1); exit}')
fi
 
# If still not found, try to get the details from Apple
if [ -z "$model_name" ]
then
    # Redirect standard error as macOS 10.10.x has an unfixed bug with system_profiler
    serial_number=$(ioreg -l | awk -F "\"" '/IOPlatformSerialNumber/ {print $(NF-1)}')

    # Get serial number length, note wc includes new line character
    # For serials of 11 characters, last 3 digits of serial required
    # For serials of 12 characters, last 4 digits of serial required
    serial_number_length=$(echo $serial_number | wc -c)

    # wc also adds empty spaces
    case $serial_number_length in
  
        *"13"*)
            serial_number=$(echo $serial_number | awk '{print substr( $NF, length($NF) - 3, length($NF) ) }')
            ;;
        *"12"*)
            serial_number=$(echo $serial_number | awk '{print substr( $NF, length($NF) - 2, length($NF) ) }')
            ;;
        *)
            echo "$mac_model"
            exit 0
            ;;
    esac

    model_name=$(curl -s https://support-sp.apple.com/sp/product\?cc=$serial_number | sed 's|.*<configCode>\(.*\)</configCode>.*|\1|')

    # If this still fails, just return the hardware model details
    if [[ "$model_name" =~ "error" ]]
    then
        model_name="$mac_model"
    fi
fi

if [ -z $model_name ]
then
    echo "$mac_model"
else
    echo "$model_name"
fi
 
exit 0