Greetings and salutations!
I have a script that displays a prompt to rename the Mac during provisioning to my org's naming convention. It was working until relatively recently and the policy logs show it fails with "Script result: 69:189: execution error: Application isn’t running. (-600)". my guess is some Apple update broke the script but scripting is a weaker part of my skills so help would be fantastic. Thanks!
#!/bin/zsh
defaults=/usr/bin/defaults
CurrentUser=$(/usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ {print $3}')
MacName=$(sudo -u "$CurrentUser" /usr/bin/osascript -e 'tell application "System Events" to set MacName to text returned of (display dialog "Enter the new Computer Name:" buttons "Continue" default button "Continue" default answer "" with icon 1)')
scutil --set ComputerName "$MacName"
scutil --set HostName "$MacName"
scutil --set LocalHostName "$MacName"
defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string "$MacName"
/usr/bin/dscacheutil -flushcache