Skip to content

Instantly share code, notes, and snippets.

@matthewbodaly
Last active June 6, 2019 20:36
Show Gist options
  • Save matthewbodaly/f2a20964f8110b10c09f2b8e9cc5a4d0 to your computer and use it in GitHub Desktop.
Save matthewbodaly/f2a20964f8110b10c09f2b8e9cc5a4d0 to your computer and use it in GitHub Desktop.
Rename a computer
#!/bin/bash
# copied from https://jamfnation.jamfsoftware.com/discussion.html?id=16743
# v 1.1 cleaned up old way of doing things
name=$(osascript -e 'Tell application "System Events" to display dialog "Please enter a name for your computer or select Cancel." default answer ""' -e 'text returned of result' 2>/dev/null)
if [ $? -ne 0 ]
then # user cancel
exit
elif [ -z "$name" ]
then # loop until input or cancel
osascript -e 'Tell application "System Events" to display alert "Please enter a name or select Cancel... Thanks!" as warning'
else [ -n "$name" ] # user input
break
fi
done
# renames computer
# scutil --set ComputerName $name
# renames computer using JSS
jamf setComputerName -name $name
jamf recon
#!/bin/bash
# this is a bit of overkill but it does the thing and i should clean this up.
loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");'`
ComputerName=`/usr/bin/osascript <<EOT
tell application "System Events"
activate
display dialog "Enter Computer Name" default answer ""
set ComputerName to (text returned of result)
end tell
EOT`
scutil --set HostName $ComputerName
scutil --set LocalHostName $ComputerName
scutil --set ComputerName $ComputerName
jamf setComputerName -name $ComputerName
jamf recon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment