Skip to content

Instantly share code, notes, and snippets.

@ealize
Forked from jacobsalmela/osx-set-all-names.sh
Last active September 12, 2018 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ealize/8692131ee2795763f025d2febbbae7f7 to your computer and use it in GitHub Desktop.
Save ealize/8692131ee2795763f025d2febbbae7f7 to your computer and use it in GitHub Desktop.
Set all four OS X computer names using a script.
#!/bin/bash
read -p "Enter new machine name: " MAC_NAME
# Bonjour name ending in .local
scutil --set LocalHostName "$MAC_NAME"
# Friendly name shown in System Preferences > Sharing
scutil --set ComputerName "$MAC_NAME"
# The name recognized by the hostname command
scutil --set HostName "$MAC_NAME"
# Save the computer's serial number in a variable so it can be used in the next command.
serialNum=$(ioreg -l | awk '/IOPlatformSerialNumber/ { split($0, line, "\""); printf("%s\n", line[4]); }')
# Set the NetBIOS name as the serial number
defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string "$serialNum"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment