Skip to content

Instantly share code, notes, and snippets.

@markeissler
Forked from jacobsalmela/osx-set-all-names.sh
Created May 29, 2018 13:56
Show Gist options
  • Save markeissler/440fa1844c831c7f1bd3238799e7df5a to your computer and use it in GitHub Desktop.
Save markeissler/440fa1844c831c7f1bd3238799e7df5a 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