This Bash script allows IT administrators to assign a Jamf-managed macOS device to a specific Site using SwiftDialog for the user interface.
Instead of dynamically fetching sites via the Jamf API (which SwiftDialog currently struggles to display from JSON), this v1.0 version uses a static, predefined list of sites and their IDs. The selected site is then updated on the target Mac's Jamf record via the Jamf Pro API.
Author: Juan Garcia
Version: 1.0
- Displays a drop-down list of sites via SwiftDialog.
- Pulls Computer ID (jssID) and Serial Number from a local plist file.
- Uses Jamf's OAuth 2.0 flow for secure API authentication.
- Sends a PATCH request to
/api/v1/computers-inventory-detail/{id}to update the Site ID. - Sorts sites alphabetically while keeping IDs matched.
- Deployment Workflow to use Jamf Pro with.
- macOS
- SwiftDialog installed at
/usr/local/bin/dialog jqinstalled for JSON parsing- Jamf Pro instance with API access
- A local plist file containing:
jssID(Jamf Computer ID)serialNumber(Mac serial number)- More information on creating - (rtrouton)
- Jamf API Client ID and Client Secret
- Jamf API Client ID with a Role that has the ability to Read, Create, and Update Computers.
- Install SwiftDialog:
brew install --cask swift-dialog
- Install
jq:brew install jq
- Place the script in your desired location (e.g.,
/usr/local/bin/SwiftDialog-SiteAssignment.sh). - Make it executable:
chmod +x /usr/local/bin/SwiftDialog-SiteAssignment.sh
- Update the configuration variables in the script with you attributes:
jamfURL="https://[yourjamfCloud].jamfcloud.com" client_id="[yourClientID]" client_secret="[yourClientSecret]" plistPath="[locationOfYourEndpointInformationPLIST]"
Run the script manually:
sudo /bin/bash /path/to/testingpolicy.shYou’ll see the image from above.
- A SwiftDialog drop-down listing your available sites.
- Once a site is selected, the script updates the Site ID in Jamf for that Mac.
You can create a jamf configuration profile with a Applications & Custom Settings and upload the plist file below.
Your plist file should be located in the path set in plistPath and contain:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>jssID</key>
<integer>123</integer>
<key>serialNumber</key>
<string>C02XXXXXXX</string>
</dict>
</plist>This script uses:
PATCH /api/v1/computers-inventory-detail/{id}
Payload:
{
"general": {
"siteId": [selectedID]
}
}- Static site list — Must be manually updated if sites change in Jamf. Sites don't tend to dynamically change that often, management for site names and id's is manual.
- SwiftDialog JSON limitation — Currently cannot directly parse API-returned JSON into the drop-down.
MIT License — Use freely, modify, and share.
