Shell script or applescript to rename computer

I need a script to rename a computer. I know how to get the computer name via a shell script

grep -A1 ‘ComputerName<’ /Library/Preferences/SystemConfiguration/preferences.plist | grep -v key | sed s/“[[:blank:]]*</*string>”//g

Is there any way to change it the name?

Would love to do it with just an applescript but i don’t think that is doable.


you thought wrong. :slight_smile: (turn on GUI scripting first though)

set NewComputerName to "New Name"

tell application "System Preferences" to activate
delay 2
tell application "System Events"
	tell process "System Preferences"
		set frontmost to true
		click menu item "Sharing" of menu "View" of menu bar 1
		delay 2
		tell window "Sharing"
			text field 1
			set value of text field 1 to NewComputerName
		end tell
	end tell
end tell
tell application "System Preferences" to quit


Script isn’t working… Computer name is not changing!
Can I do it without the script AND/OR to be a root user.

How does “Apple Remote Desktop” change the computer name?


This script is working. thanks.

Only how to use this script with a managed user.
A managed user can only change the computername with an admin password.

How can a managed user (with this script) change the computername.
Can it be done with a bash script??