Posted on 01-05-2022 04:31 AM
I've included a command in the DEPNotify-Starter script which using API's connects to the server and pulls down Departments the script itself appears to work fine, checking the logs it is pulling down the Departments correctly, I'm unsure how to display the contents of that variable within DEPNotify using the DEPNotify-Starter script, so the users can select from a drop down list. If/when I can get this working I plan on doing the same for Buildings.
Thanks
01-05-2022 10:12 AM - edited 01-05-2022 10:14 AM
I threw this together rather quickly so please test, but adding this script to jamf, then adding the script to a policy & triggering that policy via custom trigger from within the depnotify main script should do exactly what you're looking for, it will create a popup window with a dropdown which departments you add to the script that reflect your departments within Jamf. Hope this helps!
#!/bin/bash
######## Prompt for Department Value, Accounting, Booking, IT or HR ########
/usr/bin/osascript -e 'tell application "System Events" to tell process "Finder"
set frontmost to true
end tell'
JamfDepartmentValue=$( /usr/bin/osascript -e "tell application \"Finder\"
set Choices to {\"Accounting\", \"Booking\", \"IT\", \"HR\"}
set SelectChoices to choose from list Choices with prompt \"Select a Department\" default items {\"Accounting\"} OK button name {\"Continue\"} cancel button name {\"Cancel\"}
end tell" )
################################ Post Department #####################################
/usr/local/bin/jamf recon -department ${JamfDepartmentValue}
Posted on 01-05-2022 01:35 PM
@SarelErwee Maybe I'm just having déjà vu, but I could swear I saw a post just like yours yesterday or the day before. Was that you? Did you post again, or is it just a coincidence that someone posted an almost identical question?
Anyway, I had posted to that other thread (or thought I did) and said this is possible to do. You have to pull the Building and Department values from the Jamf Pro API, and then use that in the script to populate the depnotify.plist file to set up the application's interface. Here is a sample of how I've done it. Please keep in mind this is NOT a complete script. You'll have to graft this into your existing script, paying careful attention to variable names and other items to ensure they all match up.
#!/bin/bash
APIUSER="$4"
APIPASS="$5"
LOGGED_IN_USER=$(stat -f%Su /dev/console)
CONFIG_PLIST_PATH="/Users/${LOGGED_IN_USER}/Library/Preferences/menu.nomad.DEPNotify.plist"
function getAPIValues ()
{
## Pull values from the enrolled to Jamf Pro server using the API
## Jamf Pro URL this Mac is enrolled to
JP_URL=$(/usr/bin/defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url | sed 's/\/$//')
## Get list of Buildings assigned in Jamf Pro
BUILDINGS=$(curl -H "Accept: application/xml" -sku "${APIUSER}:${APIPASS}" "${JP_URL}/JSSResource/buildings" -X GET | xmllint --format - | awk -F'>|<' '/<name>/{print $3}')
## Get list of Departments assigned in Jamf Pro
DEPARTMENTS=$(curl -H "Accept: application/xml" -sku "${APIUSER}:${APIPASS}" "${JP_URL}/JSSResource/departments" -X GET | xmllint --format - | awk -F'>|<' '/<name>/{print $3}')
## Create buildings array
BUILDS+=("-None-")
while read NAME; do
BUILDS+=("${NAME}")
done < <(printf '%s\n' "$BUILDINGS")
## Create departments array
DEPTS+=("-None-")
while read NAME; do
DEPTS+=("${NAME}")
done < <(printf '%s\n' "$DEPARTMENTS")
}
## Determine if we should attempt grabbing values from Jamf Pro using the API
if [ ! -z "$APIUSER" ] && [ ! -z "$APIPASS" ]; then
getAPIValues
else
BUILDS=("Unknown")
DEPTS=("Unknown")
fi
## Here, create the variables to be used when creating the plist file for DEPNotify UI
## THIS IS NOT COMPLETE. Add in whatever else is needed here from your main script
## Set values for Pop-up #1
## Pop-up menu 1 is for the building selection
REG_POPUP_1_LABEL="Building"
REG_POPUP_1_CONTENT="${BUILDS}"
REG_POPUP_1_HELP_TITLE="Building Selection"
REG_POPUP_1_HELP_TEXT="OPTIONAL. Choose the appropriate building."
## Set values for Pop-up #2
## Pop-up menu 2 is for the department selection
REG_POPUP_2_LABEL="Department"
REG_POPUP_2_CONTENT="${DEPTS}"
REG_POPUP_2_HELP_TITLE="Department Selection"
REG_POPUP_2_HELP_TEXT="OPTIONAL. Choose the appropriate department."
## Finsh the plist by adding in any building and department values obtained with the API
for ITEM in "${BUILDS[@]}"; do
/usr/bin/defaults write "$CONFIG_PLIST_PATH" popupButton1Content -array-add "$ITEM"
done
for ITEM in "${DEPTS[@]}"; do
/usr/bin/defaults write "$CONFIG_PLIST_PATH" popupButton2Content -array-add "$ITEM"
done
You'll need to supply an account from your Jamf server that can read at least Buildings and Departments. I don't know the exact privileges needed for it to work. but usually it has to be able to read Users as well for some reason. You can supply the creds to this account as variables as shown above ($4 and $5 for username and password, respectively), or use something like Jamf's Encrypted Strings process to obscure them a little more.
Posted on 01-05-2022 01:59 PM
Here is the thread I mentioned in my other post from a few days ago. Looks identical. Are you posting questions under different accounts? Or is this a colleague?