Skip to content

Instantly share code, notes, and snippets.

@umi-uyura
Created April 29, 2016 14:39
Show Gist options
  • Save umi-uyura/56d88db6116fb713cd422a81acdb5f2d to your computer and use it in GitHub Desktop.
Save umi-uyura/56d88db6116fb713cd422a81acdb5f2d to your computer and use it in GitHub Desktop.
To change the computer name of the Mac
#!/bin/sh
computer_name=$(scutil --get ComputerName)
local_host_name=$(scutil --get LocalHostName)
host_name=$(scutil --get HostName)
echo "Current setting: "
echo " Computer Name : $computer_name"
echo " Local Host Name : $local_host_name"
echo " Host Name : $host_name"
echo
sudo -v
read -p "The user-friendly name for the system (Computer Name): " computer_name
read -p "The local (Bonjour) host name, .local is unnecessary (Local Host Name): " local_host_name
read -p "The name associated with hostname and gethostname (Host Name): " host_name
echo
echo "Computer Name : $computer_name"
echo "Local Host Name : $local_host_name"
echo "Host Name : $host_name"
echo
echo "Are you sure? (yes or no)"
read answer
case $answer in
yes|y)
sudo scutil --set ComputerName "$computer_name"
sudo scutil --set LocalHostName "$local_host_name"
sudo scutil --set HostName "$host_name"
echo
echo "configured."
;;
*)
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment