Script issue - PPPC issue - does not make sense ?

jameson
Contributor II

When Users enroll their Mac the following scripts prompt users to pick country

#!/bin/bash

# Create folder
/bin/mkdir -p /Library/Company
/bin/chmod -R 755 /Library/Company
serialNumber=$( ioreg -c IOPlatformExpertDevice -d 2 | awk -F" '/IOPlatformSerialNumber/{print $(NF-1)}' )

# Prompt for Country
countryValue=`/usr/bin/osascript <<EOT
tell application "System Events"
    with timeout of 9999 seconds
    activate
    set theCountry to {"IDMAC", "NLMAC", "JPMAC", "USMAC"}
    set selectedCountry to {choose from list theCountry with prompt "Select Country"}
    end timeout
end tell
EOT`

# Set ComputerName|LocalHostName|HostName
scutil --set ComputerName  "$countryValue-$serialNumber"
scutil --set LocalHostName  "$countryValue-$serialNumber"
scutil --set HostName  "$countryValue-$serialNumber"

exit 0

But if often does not appear in the enrollment process and in the logs it shows

cript result: 175:231: execution error: Not authorised to send Apple events to System Events. (-1743) scutil: invalid option -- C usage: scutil interactive access to the dynamic store. or: scutil --prefs [preference-file] interactive access to the [raw] stored preferences. or: scutil [-W] -r nodename or: scutil [-W] -r address or: scutil [-W] -r local-address remote-address check reachability of node, address, or address pair (-W to "watch"). or: scutil -w dynamic-store-key [ -t timeout ] -w wait for presense of dynamic store key -t time to wait for key or: scutil --get pref or: scutil --set pref [newval] or: scutil --get filename path key pref display (or set) the specified preference. Valid preferences include: ComputerName, LocalHostName, HostName newval New preference value to be set. If not specified, the new value will be read from standard input. or: scutil --dns show DNS configuration. or: scutil --proxy show "proxy" configuration. or: scutil --nwi show network information or: scutil --nc show VPN network configuration information. Use --nc help for full command list or: scutil --allow-new-interfaces [off|on] manage new interface creation with screen locked. or: scutil --error err# display a descriptive message for the given error code scutil: invalid option -- C usage: scutil interactive access to the dynamic store. or: scutil --prefs [preference-file] interactive access to the [raw] stored preferences. or: scutil [-W] -r nodename or: scutil [-W] -r address or: scutil [-W] -r local-address remote-address check reachability of node, address, or address pair (-W to "watch"). or: scutil -w dynamic-store-key [ -t timeout ] -w wait for presense of dynamic store key -t time to wait for key or: scutil --get pref or: scutil --set pref [newval] or: scutil --get filename path key pref display (or set) the specified preference. Valid preferences include: ComputerName, LocalHostName, HostName newval New preference value to be set. If not specified, the new value will be read from standard input. or: scutil --dns show DNS configuration. or: scutil --proxy show "proxy" configuration. or: scutil --nwi show network information or: scutil --nc show VPN network configuration information. Use --nc help for full command list or: scutil --allow-new-interfaces [off|on] manage new interface creation with screen locked. or: scutil --error err# display a descriptive message for the given error code scutil: invalid option -- C usage: scutil interactive access to the dynamic store. or: scutil --prefs [preference-file] interactive access to the [raw] stored preferences. or: scutil [-W] -r nodename or: scutil [-W] -r address or: scutil [-W] -r local-address remote-address check reachability of node, address, or address pair (-W to "watch"). or: scutil -w dynamic-store-key [ -t timeout ] -w wait for presense of dynamic store key -t time to wait for key or: scutil --get pref or: scutil --set pref [newval] or: scutil --get filename path key pref display (or set) the specified preference. Valid preferences include: ComputerName, LocalHostName, HostName newval New preference value to be set. If not specified, the new value will be read from standard input. or: scutil --dns show DNS configuration. or: scutil --proxy show "proxy" configuration. or: scutil --nwi show network information or: scutil --nc show VPN network configuration information. Use --nc help for full command list or: scutil --allow-new-interfaces [off|on] manage new interface creation with screen locked. or: scutil --error err# display a descriptive message for the given error code

The strange this is then afterwards if I run the policy in self service afterwards it works fine.

I have added the PPPC profile and it is loaded when the script runs in the enrollment. So it does not make sense that it works in self service but not during enrollment. On some mac´s it actually works, while on other the pick country step is simply skipped with the above error log

1 REPLY 1

Mithrandir
New Contributor III

After reading numerous replies here, and looking at various scripts, I cobbled together the following:

#!/bin/zsh -v

sn=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
macModel=$(/usr/sbin/sysctl -n hw.model)
headCriteria="$[your_departmental_designation]"
domain="$[your_domain}"

# Need to define the non MacBooks options
if [[ "$macModel" =~ BookAir ]]; then
setModel='L'
elif [[ "$macModel" =~ BookPro ]]; then
setModel='L'
elif [[ "$macModel" =~ Book ]]; then
setModel='L'
else
setModel='D'
fi

ComputerName="$headCriteria-$sn-$setModel"
HostName="$headCriteria-$sn-$setModel-$domain"
LocalHostName="$headCriteria-$sn-$setModel"

# Set the ComputerName, HostName and LocalHostName
sudo /usr/sbin/scutil --set ComputerName "$computerName"
sudo /usr/sbin/scutil --set HostName "$hostName"
sudo /usr/sbin/scutil --set LocalHostName "$localHostName"

## Create dummy receipt to mark complete
touch /Library/Receipts/com.company.renameComplete.bom

## Update Inventory
/usr/local/bin/jamf recon

 

When run either remotely, or locally, it appears to do what it's supposed to, e.g., it runs without error--but it doesn't actually change anything!