Small pop-up window during enrollment for setting device name

imnotajamfadmin
New Contributor III

Good morning,

I am getting acclimated to JAMF and unix scripting - Im looking for a way to have a tiny pop-up gui that shows during enrollment where I can easily set the device name. Ideally, what I type in would kick off:

set --HostName

set --LocalHostName

set --ComputerName

We do not utilize zero touch enrollment at this time, we dont have enough devices to really justify it. However, having a tool like this would really improve my process.

Thank you for any help!

4 REPLIES 4

fedagain
Contributor

You can do something like this in AppleScript......

 

set compName to do shell script "hostname -s"

set the compN to text returned of ¬

(display dialog "**Name Computer**

 

please click Continue" default answer compName buttons {"Exit", "Continue"} default button 2 with title ("Name Computer"))

set compName to compN

do shell script "scutil --set ComputerName " & compName & ¬

";scutil --set HostName " & compName & ¬

";scutil --set LocalHostName " & compName password "" with administrator privileges

do shell script "/usr/local/bin/jamf recon" with administrator privileges

 

IF YOU NEED TO INCORPORATE AN ADMIN PWD......

 

set compName to do shell script "hostname -s"

set the compN to text returned of ¬

(display dialog "**Name Computer**

 

please click Continue" default answer compName buttons {"Exit", "Continue"} default button 2 with title ("Name Computer"))

set compName to compN

do shell script "scutil --set ComputerName " & compName & ¬

";scutil --set HostName " & compName & ¬

";scutil --set LocalHostName " & compName password "1234" with administrator privileges

howie_isaacks
Valued Contributor II

What's your naming scheme? You could write a script that will automatically name the Mac, so a pop-up won't be necessary. About 4 years ago I wrote a script that would display a pop-up dialog box for the user to input the computer name. At the time, the name scheme I used was FirstName-LastName. Later I stopped using the user's name in the computer name since that could cause security and privacy issues. Here's what I wrote. It should be easy to modify the text displayed to the user. What ever they enter will be the name of the Mac. You could either add "/usr/loca/jamf/bin/jamf recon" to the script or just add the inventory step in the policy that deploys the script. I have some other naming scripts that work automatically so no pop-up is needed. I'm happy to share them.

 

#!/bin/sh
computerName=$(osascript -e 'tell application "SystemUIServer"
set myComputerName to text returned of (display dialog "Please give this Mac a name then click Submit. Use First-Last name format." default answer "" with title "Asset ID" buttons {"Submit"} with icon caution)
end tell')

/usr/sbin/scutil --set ComputerName "${computerName}"
/usr/sbin/scutil --set LocalHostName "${computerName}"
/usr/sbin/scutil --set HostName "${computerName}"

dscacheutil -flushcache

 

 

mickgrant
Contributor III

This Script will do what you are after
Though I agree with the other posters that you should probably be using a naming convention,  and with the jamf setcomputername command it actually very simple to do. 
Have a look at the documentation on it HERE 

#!/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

 

imnotajamfadmin
New Contributor III

I apologize for abandoning this thread, I have had zero time at work to regroup and focus on this. Im also a windows admin and thats the main focus. We have JAMF, I am the only JAMF admin, but I have it in a place where it just works and there havent been complaints. Plans to improve are on the horizon which is why Im trying to get some script help with threads like these.

Thank you all for your suggestions.

We do have a naming scheme, but it goes "department-MC(mac computer)-internal inventory tag #" so something like ABC-MC-U1234567

Ive recently automated our windows deployment naming schemes by utilizing bios asset tag and smbios/wmi. Anything similar with mac? Thanks again.