Created
November 1, 2017 13:53
-
-
Save talkingmoose/99a3b5b45b1c6e8e680429f786bebb5e to your computer and use it in GitHub Desktop.
Customer script for renaming a Mac using a Self Service policy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
ComputerName=$( osascript <<'END' | |
set serialNumber to do shell script "system_profiler SPHardwareDataType | grep 'Serial Number' | awk -F: '{ print $2 }' | xargs" | |
set computername to "" | |
repeat while computername is "" or computername is "Type Computer Name Here" | |
with timeout of 172800 seconds -- 2 days | |
tell application "System Events" | |
set computername to display dialog "Please read thoroughly before setting computer name. Computer Name is typically on a sticker which may be on the outside of the device. | |
Cart Based: (Typically Macbooks) | |
Location+C+CartNumber-ExtensionName+DeviceNumber (Ex01-MB01) | |
Stationary Based: (Typically iMacs and Mac Minis) | |
Location-RoomNumber-ExtensionName+Device Number (Ex-2100-IM01) | |
User Assigned Based: (Typically Macbooks) | |
Location-ExtensionName+DeviceNumber (Ex-MB01) | |
" default answer "Type Computer Name Here" with title "Computer Name" | |
end tell | |
end timeout | |
if button returned of computername is "Cancel" then | |
return | |
end if | |
set computername to text returned of computername | |
end repeat | |
tell application "System Events" | |
display dialog "Computer Name Set to: " & computername buttons {"OK"} default button {"OK"} with title "Computer Name" with icon file POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/com.apple.macbook-retina-silver.icns" giving up after 10 | |
end tell | |
return computername | |
END | |
) | |
#Set New Computer Name | |
echo $ComputerName | |
scutil --set ComputerName $ComputerName | |
scutil --set LocalHostName $ComputerName | |
scutil --set HostName $ComputerName | |
echo Rename Successful | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment