Host Name Change

IT-Chris
New Contributor III

Hello I'm trying to modify a script I had for renaming computers
This is my current setup :
I want to pull the current system name as the default answer. (system info)'s Computer name. This uses to work but not with this setup script. Reason I want this script is so if the user uses the cancel button it don't use the password as the computer name.

thanks for any help or answers to this issue.

Password for Local Account

setid=$(osascript -e 'Tell application "System Events" to display dialog "Enter Account password:" with hidden answer default answer ""' -e 'text returned of result' 2>/dev/null)

Set Computer Name

while :; do # Loop until valid input is entered or Cancel is pressed. ComputerName=$(osascript -e 'Tell application "System Events" to display dialog "Enter Computer Name:" default answer " want current hostname here" ' -e 'text returned of result' 2>/dev/null) if (( $? )); then exit 1; fi # Abort, if user pressed Cancel. ComputerName=$(echo -n "$ComputerName" | sed 's/^ //' | sed 's/ $//') # Trim leading and trailing whitespace. if [[ -z "$ComputerName" ]]; then # The user left the project name blank. osascript -e 'Tell application "System Events" to display alert "Please Enter Computer name; please try again." as warning' >/dev/null # Continue loop to prompt again. else # Valid input: exit loop and continue. break fi
done

scutil --set HostName $ComputerName

scutil --set LocalHostName $ComputerName

scutil --set ComputerName $ComputerName

/usr/local/bin/jamf recon

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

Do you mind updating your post to enclose the entire script in the script markup tags? That's generated with the button above the post field that looks like >_
You can also place 3 backticks ( like so: ``` ) at the top of the script and the end of it. This will make it easier for us to read your script and make suggestions on what to change.

View solution in original post

1 REPLY 1

mm2270
Legendary Contributor III

Do you mind updating your post to enclose the entire script in the script markup tags? That's generated with the button above the post field that looks like >_
You can also place 3 backticks ( like so: ``` ) at the top of the script and the end of it. This will make it easier for us to read your script and make suggestions on what to change.