Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talkingmoose/baa8aef1502df7d168baf7fbb304bba8 to your computer and use it in GitHub Desktop.
Save talkingmoose/baa8aef1502df7d168baf7fbb304bba8 to your computer and use it in GitHub Desktop.
Resources for Jamf's "Script 201 for Apple Admins" webinar on June 18, 2020.
"Scripting 101 for Apple Admins" Webinar
Video: https://www.jamf.com/resources/webinars/scripting-101-for-apple-admins/
Discussions: https://www.jamf.com/jamf-nation/discussions/32391/scripting-101-for-apple-admins-webinar
PDF reference: https://www.jamf.com/blog/scripting-basics-for-everyone/
Time Zone script:
https://www.jamf.com/jamf-nation/third-party-products/files/836/settimezone-sh-set-the-time-zone
Jamf Training Catalog, Scripting series
https://trainingcatalog.jamf.com/series/scripting
#!/bin/zsh
# assign long path to JamfHelper to a shorter variable
jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
# run JamfHelper with input from script parameters
"$jamfHelper" -windowType "$4" \
-heading "$5" \
-description "$6" \
-icon "$7" &
#!/bin/zsh
echo
echo $1 $2 $3 $4 $5
echo
echo $5 $3 $1 $2 $4
echo
In Terminal:
/path/to/paramters.zsh Mary had a little lamb
Mary had a little lamb
lamb a Mary had little
echo echo or print what we say
> redirect to a file
$( command ) run a command
!$ repeat the last argument
cat read a file
Using 'echo' and 'cat'
echo 'Hello, World!'
echo 'Technician: Martin Moose' >> ~/Desktop/provision.txt
echo "Date: $( /bin/date +%y-%m-%d )" >> !$
echo "Department: Graphics" >> !$
/bin/cat ~/Desktop/provision.txt
Using 'defaults'
/usr/bin/defaults write ~/Desktop/provision.plist Technician 'Martin Moose'
/usr/bin/defaults write ~/Desktop/provision.plist Date $( /bin/date '+%y-%m-%d' )
/usr/bin/defaults write ~/Desktop/provision.plist Department 'Graphics'
/usr/bin/defaults read ~/Desktop/provision.plist Technician
#!/bin/zsh
# assign long path to JamfHelper to a shorter variable
jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
# get information about the current user
currentUser=$( /usr/bin/stat -f "%Su" /dev/console )
fullName=$( /usr/bin/id -F "$currentUser" ) # e.g. "Martin Moose"
echo "Provisioning user is $fullName ($currentUser)"
# AppleScript command to ask the currently logged in user to choose a department
asCommand="choose from list {\"Accounting\", \"Sales\", \"Kiosk\"} with prompt \"Hello, $fullName! Let's prepare your Mac. To start, choose your department below...\" with title \"Prepare your Mac\""
# run the command
department=$( /usr/bin/osascript -e "$asCommand" )
echo "Provisioned for department $department"
# AppleScript command to ask the currently logged in user to enter an asset tag
asCommand="text returned of (display dialog \"Enter this Mac's asset tag (see bottom of computer)...\" default answer \"\" with title \"Prepare your Mac\")"
# run the command
assetTag=$( /usr/bin/osascript -e "$asCommand" )
echo "Device asset tag is $assetTag"
# build this Mac for the selected department
# global settings
/usr/local/bin/jamf policy -event settimezonechicago
if [[ "$department" = "Accounting" ]]; then
echo "Provisioning this Mac for Accounting"
/usr/local/bin/jamf policy -event installchrome
/usr/local/bin/jamf policy -event installoffice
elif [[ "$department" = "Sales" ]]; then
echo "Provisioning this Mac for Sales"
/usr/local/bin/jamf policy -event installchrome
/usr/local/bin/jamf policy -event installoffice
/usr/local/bin/jamf policy -event installzoom
else
echo "Provisioning this Mac as a kiosk"
/usr/local/bin/jamf policy -event installchrome
/usr/local/bin/jamf policy -event installzoom
fi
# update Jamf Pro inventory
"$jamfHelper" -windowType "fs" \
-heading "Preparing your Mac..." \
-description "Updating inventory" \
-icon "/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns" &
/usr/local/bin/jamf recon -assetTag "$assetTag" -department "$department" -endUsername "$currentUser"
# create admin folder
"$jamfHelper" -windowType "fs" \
-heading "Preparing your Mac..." \
-description "Creating admin folder" \
-icon "/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns" &
/bin/mkdir -p "/Library/Talking Moose Industries"
# create provisioning receipt
"$jamfHelper" -windowType "fs" \
-heading "Preparing your Mac..." \
-description "Writing provisioning receipt" \
-icon "/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns" &
/usr/bin/defaults write "/Library/Talking Moose Industries/receipt.plist" provisiondate -date $( /bin/date "+%Y-%m-%d" )
/usr/bin/defaults write "/Library/Talking Moose Industries/receipt.plist" provisioner -string "$currentUser"
/usr/bin/defaults write "/Library/Talking Moose Industries/receipt.plist" department -string "$department"
/usr/bin/defaults write "/Library/Talking Moose Industries/receipt.plist" assettag -string "$assetTag"
"$jamfHelper" -windowType "fs" \
-heading "Preparing your Mac..." \
-description "Restarting your Mac in one minute" \
-icon "/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns" &
# restart the Mac
/sbin/shutdown -r +1 &
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment