Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rename your computer depending on your chassis+yourmacserialnumber
#!/bin/bash
# uniMIS renamer script -- use with ComputerName name below
# By Gilbert Palau, Enterprise OS X - www.enterpriseosx.com
#
# this script renames the mac by chassi type + serial number: ??-SERIAL
#
# variables:
laptop="ML-"
workstation="MW-"
server="S-"
tld="your.network.com"
# grabbing mac serial number...
serial=$(ioreg -l |grep "IOPlatformSerialNumber"|cut -d ""="" -f 2|sed -e s/[^[:alnum:]]//g)
# and model name...
model=$(ioreg -l |grep "product-name" |cut -d ""="" -f 2|sed -e s/[^[:alnum:]]//g | sed s/[0-9]//g)
# renaming based on model ie. prefix-computerserial.tld
case "$model" in
"MacBookPro" )
/usr/sbin/scutil --set ComputerName "$laptop$serial"
/usr/sbin/scutil --set LocalHostName "$laptop$serial"
/usr/sbin/scutil --set HostName "${laptop}${serial}.${tld}"
echo "$model"
echo "$laptop$serial"
echo "${laptop}${serial}.${tld}"
;;
"MacBookAir" )
/usr/sbin/scutil --set ComputerName "$laptop$serial"
/usr/sbin/scutil --set LocalHostName "$laptop$serial"
/usr/sbin/scutil --set HostName "${laptop}${serial}.${tld}"
echo "$model"
echo "$laptop$serial"
echo "${laptop}${serial}.${tld}"
;;
"MacPro" )
/usr/sbin/scutil --set ComputerName "$workstation$serial"
/usr/sbin/scutil --set LocalHostName "$workstation$serial"
/usr/sbin/scutil --set HostName "${workstation}${serial}.${tld}"
echo "$model"
echo "$workstation$serial"
echo "${workstation}${serial}.${tld}"
;;
"iMac" )
/usr/sbin/scutil --set ComputerName "$workstation$serial"
/usr/sbin/scutil --set LocalHostName "$workstation$serial"
/usr/sbin/scutil --set HostName "${workstation}${serial}.${tld}"
echo "$model"
echo "$workstation$serial"
echo "${workstation}${serial}.${tld}"
;;
"Macmini" )
/usr/sbin/scutil --set ComputerName "$workstation$serial"
/usr/sbin/scutil --set LocalHostName "$workstation$serial"
/usr/sbin/scutil --set HostName "${workstation}${serial}.${tld}"
echo "$model"
echo "$workstation$serial"
echo "${workstation}${serial}.${tld}"
;;
"Xserve" )
/usr/sbin/scutil --set ComputerName "$server$serial"
/usr/sbin/scutil --set LocalHostName "$server$serial"
/usr/sbin/scutil --set HostName "${server}${serial}.${tld}"
echo "$model"
echo "$server$serial"
echo "${server}${serial}.${tld}"
;;
* )
echo "Computer model not found."
exit 0
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.