Its possible, but not easy. The Script would need to be aware of how many devices came before the Mac it was run on. A script using JAMF API could do this as it could check to see what the inventory number is for the device among many other things a local script would not be aware of. My suggestion is keep things stupid simple, unless you have a need to name things this way just use something unique like the serial number.
This is the script I use, it sets the device name to the Serial Number. you can adjust the hardware profiler stuff in lines 26/27 to set the name to whatever you want.
#!/usr/bin/env bash
#*=============================================================================
#* Script Name:
#* Created:
#* Author:
#*=============================================================================
#* Purpose: Requests input and renames computer based on Naming Conventions
#*=============================================================================
#*=============================================================================
#* GLOBAL VARIABLES
#*=============================================================================
DIV1='echo ####################################################################'
DIV2='echo --------------------------------------------------------------------'
DIV3='echo ....................................................................'
ActiveUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }' | tr "[a-z]" "[A-Z]"`
ActiveUserRealName=`dscl . -read /Users/$ActiveUser | grep RealName: | cut -c11-`
if [[ -z $ActiveUserRealName ]]; then
ActiveUserRealName=`dscl . -read /Users/$ActiveUser | awk '/^RealName:/,/^RecordName:/' | sed -n 2p | cut -c 2-`
fi
computerName=$(scutil --get ComputerName)
hostName=$(scutil --get HostName)
localHost=$(scutil --get LocalHostName)
serialNumber=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
serialNumberII=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}' | tr -d '"')
#*=============================================================================
#* FUNCTIONS
#*=============================================================================
userInfo () {
echo; $DIV1
echo "User Information:"
if [[ "$ActiveUserRealName" == "$ActiveUser" ]]; then
echo "$ActiveUserRealName (Local Admin)"
else
echo "$ActiveUserRealName ($ActiveUser)"
fi
$DIV1
}
#*=============================================================================
#* SCRIPT BODY
#*=============================================================================
userInfo
## Check & Update Computer Name
if [ "$computerName" == "$serialNumber" ]
then
echo "Computer name matches serial number, $serialNumber"
else
echo "Current Computer Name: $computerName"
echo "Computer Name does not meet standards"
echo "Changing Computer Name to match Serial Number"
scutil --set ComputerName "$serialNumber"
fi; $DIV2
## Check & Update Host Name
if [ "$hostName" == "$serialNumber" ]
then
echo "Host Name matches serial number, $serialNumber"
else
echo "Current Host Name: $hostName"
echo "Host Name does not meet standards"
echo "Changing Host Name to match Serial Number"
scutil --set HostName "$serialNumber"
fi; $DIV2
## Check & Update Local Host
if [ "$localHost" == "$serialNumber" ]
then
echo "Local Host matches serial number, $serialNumber"
else
echo "Current Local Host: $localHost"
echo "Local Host does not meet standards"
echo "Changing Local Host to match Serial Number"
scutil --set LocalHostName "$serialNumber"
fi; $DIV2
## Final Check
computerNameII=$(scutil --get ComputerName)
hostNameII=$(scutil --get HostName)
localHostII=$(scutil --get LocalHostName)
echo ""
echo "Serial number: $serialNumber"
echo "Computer Name: $computerNameII"
echo "Host Name: $hostNameII"
echo "Local Host: $localHostII"
if [[ "$computerNameII" == "$serialNumber" ]] && [[ "$hostNameII" == "$serialNumber" ]] && [[ "$localHostII" == "$serialNumber" ]]
then
echo "Computer Name satisfies naming standards"
$DIV1; exit 0
else
echo "Computer does not meet naming standards"
echo "More troubleshooting will be necessary."
$DIV1; exit 1
fi
## Perform final Recon to update computer name on Jamf
sudo jamf recon
#*=============================================================================
#* END OF SCRIPT
#*=============================================================================
with Jamf Pro in the Prestage you can set the naming convention to a csv list (comma seperated value) of all the numbers you want.
We did that for about 280 laptops a couple of years ago, one Caveat is that when you power them on its who ever contacts Jamf first gets the number so we experienced say ten laptops turned on in sequential order, you would think that the first one would be 001, second 002, and so forth. However, this is not always the case we had experiences where the first few would be the same but the fifth one would beat out the fourth in getting a name. Now for you it may not matter depending on deployment, for us we just had to check the name before we applied asset tag labels and assign it to a user.
Your other option is to know the serial numbers and then after the fact use MUTT to mass update the serial numbers to actual names.