Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
talkingmoose / Get App Install Date.zsh
Created April 10, 2020 18:19
Returns the installation date for an app installed uisng an Apple Installer package. In Terminal run /path/to/script /path/to/Bundle.app (drag the app into the window).
#!/bin/bash
# in Terminal run /path/to/script /path/to/Bundle.app
installedApp=$1
# get the app's bundle identifier
bundleID=$( /usr/bin/defaults read "$installedApp/Contents/Info.plist" CFBundleIdentifier )
# get the installation epoch date for the bundle identifier
installEpoch=$( /usr/sbin/pkgutil --pkg-info="$bundleID" | /usr/bin/grep "install-time" | /usr/bin/awk '{ print $2 }' )
@talkingmoose
talkingmoose / Jamf Pro Provisioning 2.zsh
Created November 16, 2020 06:25
Runs when called by a Jamf Pro policy triggered by Enrollment Complete. Installs third party software that Apple's Volume Purchase Program (VPP) cannot install and runs maintenance routines (bind to Active Directory, set time zone etc.).
#!/bin/zsh
<<'ABOUT_THIS_SCRIPT'
-----------------------------------------------------------------------
Written by:William Smith
Professional Services Engineer
Jamf
bill@talkingmoose.net
@talkingmoose
talkingmoose / High Sierra-compatible Macs (regex).txt
Last active August 23, 2023 14:12
Regex looks for all Mac models compatible with High Sierra. May include newer models that don't support High Sierra.
Model information: https://support.apple.com/kb/sp765
Published Date: September 12, 2018
(MacBookAir[3-8]|MacBookPro([7-9]|1[0-6])|MacPro[5-6]|iMac1[3-9]?|MacBook(10|[6-9])|Macmini[4-8]),\d
pattern matches:
https://support.apple.com/en-us/HT201608
@talkingmoose
talkingmoose / Enable all macOS software updates.bash
Last active August 9, 2023 21:37
The /Library/Preferences/com.apple.SoftwareUpdate.plist seems impervious to being managed via configuration profile (at least on macOS Mojave). While not enforced management, add this script to a Jamf policy and run it on a routine basis such as once per week on scoped Macs.
#!/bin/bash
/usr/bin/defaults write /Library/Preferences/com.apple.SoftwareUpdate.plist AutomaticCheckEnabled -bool TRUE
/usr/bin/defaults write /Library/Preferences/com.apple.SoftwareUpdate.plist AutomaticDownload -bool TRUE
/usr/bin/defaults write /Library/Preferences/com.apple.SoftwareUpdate.plist AutomaticallyInstallMacOSUpdates -bool TRUE
/usr/bin/defaults write /Library/Preferences/com.apple.SoftwareUpdate.plist ConfigDataInstall -bool TRUE
/usr/bin/defaults write /Library/Preferences/com.apple.SoftwareUpdate.plist CriticalUpdateInstall -bool TRUE
/usr/bin/defaults write /Library/Preferences/com.apple.commerce.plist AutoUpdate -bool TRUE
exit 0

STEP 1

Generate a key pair on your Master distribution point (DP) that the script will use for authentication to each of your remote DPs, by running the following command in Terminal (copy/paste).

/usr/bin/ssh-keygen -q -t rsa -f "$HOME/.ssh/jamfMasterDP" -N ""  

This will create your private key and public key files in your home folder:

@talkingmoose
talkingmoose / MegaPKGr.zsh
Last active June 26, 2023 05:37
The pkgbuild binary and Jamf Composer don't support adding single files of 8 GB or more to a package. Some apps like Install macOS Big Sur.app include files larger than 8 GB in their bundles. This script will create a deployable PKG file from apps whose bundles include those large files.
#!/bin/zsh
:<<ABOUT_THIS_SCRIPT
-------------------------------------------------------------------------------
Written by:William Smith
Professional Services Engineer
Jamf
bill@talkingmoose.net
https://gist.github.com/e9ed319226c6da30dd633725e48a97b0
@talkingmoose
talkingmoose / iOS and iPadOS 17 compatible devices (regex)
Last active June 22, 2023 16:28
Regex looks for all iPhone and iPad models compatible with iOS or iPadOS 17. May not be up-to-date with newly released models.
https://www.apple.com/ios/ios-17-preview/
https://www.apple.com/ipados/ipados-17-preview/
Published Date: June 5, 2023
Verification: https://regex101.com/r/m9HV8T/3
1) Exact regex — Matches major model identifier numbers based on Jamf's hardware model identifiers list (more accurate):
^iPhone1[1-5],\d|iPad([7-9]|1[1-4]),\d+$
@talkingmoose
talkingmoose / Delete account from current user's Internet Accounts.sh
Last active June 21, 2023 19:24
Example for removing specific account from System Preferences > Internet Accounts for the current user.
#!/bin/bash
# get name of currently logged in user
currentUser=$( /usr/bin/stat -f "%Su" /dev/console )
echo "Current user is $currentUser."
# get current user's home folder
homeFolder=$( /usr/bin/dscl . read "/Users/$currentUser" NFSHomeDirectory | /usr/bin/awk -F ": " '{ print $2 }' )
# remove account by description name from Accounts sqlite database
/usr/bin/sqlite3 "$homeFolder/Library/Accounts/Accounts4.sqlite" 'DELETE FROM ZACCOUNT WHERE ZACCOUNTDESCRIPTION = "Exchange"'
@talkingmoose
talkingmoose / Big Sur-compatible Macs (regex)
Last active June 7, 2023 19:50
Regex looks for all Mac models compatible with macOS Big Sur. May not be up-to-date with newly released models.
Model information: https://support.apple.com/en-us/HT211238
Published Date: October 25, 2021
Verification: https://regex101.com/r/7nnq4T/13
This regex is complete. Apple is no longer creating Big Sur compatible Macs.
(MacBook(10|9|8)|MacBookAir(10|[6-9])|MacBookPro1[1-7]|Macmini[7-9]|MacPro[6-7]|iMacPro1),\d|iMac(14,4|1[5-9],\d|2[01],\d)
@talkingmoose
talkingmoose / Managed Apple admin password last set time.zsh
Created June 2, 2023 20:07
Reads managed Apple admin account for date and time of last password change and reports in ISO 8601 format.
#!/bin/zsh
# get LAPS account username
lapsUsername=$( /usr/libexec/PlistBuddy -c "Print :Users:0:shortName" /var/db/ConfigurationProfiles/Settings/.setupUser )
# read LAPS account for password information
userPasswordInfo=$( /usr/bin/dscl . read "/Users/$lapsUsername" accountPolicyData | /usr/bin/tail -n +4 )
# extract Unix epoch date from account password information
passwordChangeDateEpoch=$( /usr/bin/xpath -e '//key[text()="passwordLastSetTime"]/following-sibling::real[1]/text()' 2>/dev/null <<< "$userPasswordInfo" )