Set new computer Name and update in Jamf Pro

kevin_neely
New Contributor III

Small shop so there not much need to automate much but to Rename laptops we've been editing them in Jamf Pro and then running a Policy that connects script:

!/bin/bash

ComputerName="$4"
scutil --set HostName $ComputerName
scutil --set LocalHostName $ComputerName
scutil --set ComputerName $ComputerName

To an "App" made available via scoping in Self Service. It works but seems like I'm doubling my workload.

I'd like to keep the Self Service app and initiate the naming from it using a script like:

!/bin/bash

newName=$( osascript -e 'text returned of (display dialog "Enter a new name for your Mac..." default answer "" with title "Name Your Computer" with icon file posix file "/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns")' )
scutil --set ComputerName "$newName"
echo "Setting ComputerName to $newName"
exit 0

This 2nd script works if I run it from Terminal on the laptop but cannot get it to work on a cloned version of the original Self Service app. I was hoping that if I could get the 2nd script to initiate through Self Service that the "Update Inventory" option under Maintenance could then push that new name to Jamf Pro. I'm fairly certain I'm chasing moondust with this last part, but would still like to get the 2nd script working as a part of an app.

Any help appreciated.

4 REPLIES 4

sharriston
Contributor III

Have you tried instead of using scutil using the Jamf binary to set the computer name. I found it much easier to manage using sudo jamf setcomputername -name $newName. Here is my working script for the issue you are describing.

#!/bin/bash

username=$(/usr/bin/osascript<<END
tell application "System Events"
activate
set the answer to text returned of (display dialog "Please enter the computer name" default answer "" buttons {"Rename"} default button "Rename")
end tell
END)

echo $username
/usr/local/bin/jamf setcomputername -name $username

/usr/local/bin/jamf recon

Hi
This works Fantastic, just 1 q about this. 

It added an icon on the desktop.
And it cant be remove

Got a quick fix for this?

Thanks

I've got the same issue going on with the desktop icon after renaming. Trying to dig into it and find a solution. Anyone found anything on this yet?

kevin_neely
New Contributor III

That did it! Fantastic. Appreciate the help.