Skip to content

Instantly share code, notes, and snippets.

@jacobsalmela
Created January 12, 2015 16:38
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jacobsalmela/b6d3144bc01809a58797 to your computer and use it in GitHub Desktop.
Save jacobsalmela/b6d3144bc01809a58797 to your computer and use it in GitHub Desktop.
Set all four OS X computer names using a script.
#!/bin/bash
# Bonjour name ending in .local
scutil --set LocalHostName "My-iMac"
# Friendly name shown in System Preferences > Sharing
scutil --set ComputerName "My-iMac"
# The name recognized by the hostname command
scutil --set HostName "My-iMac"
# 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