Hey all,
A number of years ago I inherited a Jamf platform that I am trying to improve and clean up. We have a policy of naming computers of your choice. Currently, it consists of three scripts, one of which is an AppleScript to bring up a dialog box where you can enter the desired name of the computer.
This solution has worked fairly well until about a year ago. Now you have to run the script twice for it to work, at least for Ventura and Sonoma.
The script looks like below and I was wondering if someone could help me, give me some tips to make it work better so that you don't have to run it twice?
Thanks in advance.
First script (how it's listed in Jamf policy)
#/bin/sh
#Skript som sätter en raett hostname osv. - Made by Marten B. BK.IT
#define variables
name=$(sudo /usr/sbin/scutil --get ComputerName)
sname=$(echo "$name" | tr -cd '[[:alnum:].-]')
# set computernames
sudo /usr/sbin/scutil --set HostName "$name"
sudo /usr/sbin/scutil --set LocalHostName "$sname"
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string "$sname"
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
exit 0;
Second script
#!/bin/bash
sudo jamf recon
sudo jamf policy
Third script (AppleScript)
display dialog ”Set desired computer name: " default answer "like: SE304041-teacher" with icon note buttons {"Cancel", "Continue"} default button "Continue"
set ComputerName to text returned of result
display dialog ComputerName & " will be set as computer name.." with icon stop buttons {"OK"} default button "OK"
do shell script "/usr/sbin/scutil --set ComputerName " & ComputerName & space & "setlocalsubnetname " & ComputerName with administrator privileges