I have a script that prompts a tech to set the department of a computer:
#!/bin/sh
## Establish API Credentials
# https://github.com/jamfit/Encrypted-Script-Parameters
function DecryptString() {
# Usage: ~$ DecryptString "Encrypted String" "Salt" "Passphrase"
echo "${1}" | /usr/bin/openssl enc -aes256 -d -a -A -S "${2}" -k "${3}"
}
apiUserEncrypt=$4
apiPassEncrypt=$5
apiUsername=$(DecryptString $apiUserEncrypt 'salt' 'passphrase')
apiPassword=$(DecryptString $apiPassEncrypt 'salt' 'passphrase')
## Use API to get computer Site from UUID
# Get computer's UUID
compUUID=$(system_profiler SPHardwareDataType | awk '/UUID/ { print $3; }')
compRaw=$(curl https://jssurl/JSSResource/computers/udid/${compUUID} --user "$apiUsername:$apiPassword")
echo $compRaw
compSite=$(echo $compRaw | xpath '//general/site/name' 2>&1 | awk -F'<name>|</name>' '{print $2}')
echo "compSite is"$compSite
if [[ $compSite == *"Example" ]]; then
deptName="Example"
elif [[ $compSite = *"Example2" ]]; then
deptName="Example2"
elif [[ $compSite == *"Example3" ]]; then
deptName="Example3"
fi
echo "deptName is "$deptName
## Use API to get list of departments
deptRaw=$(curl https://jssurl/JSSResource/departments --user "$apiUsername:$apiPassword")
echo $deptRaw
# https://bryson3gps.wordpress.com/2014/03/30/the-jss-rest-api-for-everyone/
deptList=$(echo $deptRaw | xpath '//department/name' 2>&1 | awk -F'<name>|</name>' '{print $2}')
echo $deptList
if [ -z "$deptName" ]; then
echo "deptName not defined"
else
for department in ${deptList[@]}
do
if [[ $department == "$deptName"* ]]; then
# https://macscripter.net/viewtopic.php?id=35318
f=${department##*/}
if [ "${f:0:1}" = "_" ] ; then
echo "NOT Processing $department" 1>&2 # for now just a test
else
if [[ ! -z ${deptParsed} ]] ; then
deptParsed=${deptParsed}","
fi
echo "Processing $department" 1>&2
deptParsed=${deptParsed}"""${f}""" # to create "item1","item2","item..n"
fi
done
# https://macscripter.net/viewtopic.php?id=35318
deptChosen="$(/usr/bin/osascript -e 'tell application "System Events" to activate' -e 'tell application "System Events" to return (choose from list {'"$deptParsed"'} with prompt "Choose a Department:" with title "Department Chooser" OK button name "Select" cancel button name "Quit")')"
fi
sudo /usr/local/bin/jamf recon -department "$deptChosen"
sudo /usr/local/bin/jamf recon
If I run this in Self Service it works fine. However if I try to run it on enroll and have Console open to jamf.log, I see that it starts to run the policy, then hangs, then moves onto the next policy without opening up the AppleScript window.
Any idea why this would happen? I'd like to set this on enroll if possible.
