Posted on 05-10-2018 08:44 AM
have a script that I'm calling via Self Service and it works perfectly. When I have another policy call the same script, it doesn't work quite right. I'll see in the logs a line:271:370: execution error: No user interaction allowed. (-1713)
below is the script. It has Apple Script at the beginning to popup a window with a list of selections and then ends with basic shell scripting.
#!/bin/sh
nameCode=`/usr/bin/osascript <<EOT
set locations to {"Office 1", "Office 2", "Office 3"}
set choice to (choose from list locations with prompt "Please select the Office that best describes your location")
set city to the result
set code to city as text
if (code = "Office 1") then
set nameCode to "DAL"
else if (code = "Office 2") then
set nameCode to "ATL"
else if (code = "Office 3") then
set nameCode to "BUR"
else
set nameCode to "CORP"
end if
EOT`
sn=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}' | cut -c 5-)
model=$(system_profiler SPHardwareDataType | awk '/Model Name/ {print $3}')
if [[ $model == "MacBook" ]]; then
modelCode="L"
else
modelCode="W"
fi
os="mac"
computerName=$modelCode$nameCode$os$sn
echo "computerName has been set to: $computerName"
networksetup -setcomputername $computerName
scutil --set LocalHostName $computerName
scutil --set HostName $computerName
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName $computerName
Solved! Go to Solution.
Posted on 05-10-2018 09:05 AM
The error is likely triggered by the "choose from list" command, which wants to work in the GUI, which is often forbidden by osascript and restricted by execution context. Wrappering osascript in a bash shell usually helps, but not always, as you discovered.
First, try having Self Service pop up the list. If that doesn't work, try the Launch Services command line interface to get in the correct context. Both tweaks are shown below, but untested.
nameCode=`/bin/launchctl asuser $(/usr/bin/stat -f%u /dev/console) /usr/bin/osascript <<EOT/usr/bin/osascript <<EOT
set locations to {"Office 1", "Office 2", "Office 3"}
set choice to (tell app "Self Service" to choose from list locations with prompt "Please select the Office that best describes your location")
Posted on 05-10-2018 09:05 AM
The error is likely triggered by the "choose from list" command, which wants to work in the GUI, which is often forbidden by osascript and restricted by execution context. Wrappering osascript in a bash shell usually helps, but not always, as you discovered.
First, try having Self Service pop up the list. If that doesn't work, try the Launch Services command line interface to get in the correct context. Both tweaks are shown below, but untested.
nameCode=`/bin/launchctl asuser $(/usr/bin/stat -f%u /dev/console) /usr/bin/osascript <<EOT/usr/bin/osascript <<EOT
set locations to {"Office 1", "Office 2", "Office 3"}
set choice to (tell app "Self Service" to choose from list locations with prompt "Please select the Office that best describes your location")
Posted on 05-10-2018 11:52 AM
Thank you @joshuasee !!
I've been wracking my brain as to why this wasn't working. The launchctl command worked.