Last active
October 6, 2016 18:52
-
-
Save geoffrepoli/0e5cdd1a9a34776e5d730ecfd72990a2 to your computer and use it in GitHub Desktop.
Changes HostName and LocalHostName to match ComputerName while accounting for non-ASCII characters
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/bash | |
comp_name=$(scutil --get ComputerName) | |
if [[ "$comp_name" = *[![:ascii:]]* ]]; then | |
echo "Error: Computer name contains non-ASCII characters. Please modify with the command \`scutil --set ComputerName <value>\` before running this script" | |
exit 1 | |
else | |
host_name=$(echo "$comp_name" | sed -e "s/'//g;s/ /-/g;s/\///g" | awk '{print tolower($0)}') | |
echo "Changing hostname and Bonjour name to $host_name ..." | |
scutil --set LocalHostName "$host_name" | |
scutil --set HostName "$host_name" | |
echo "Success: hostname and Bonjour name updated" | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment