Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
talkingmoose / "Early Adopter" extension attribute
Last active November 21, 2023 22:31
Self Service policy to enable end users to enroll their Macs into an "Early Adopter Program" or any other type of enrollment. Create a Smart Computer Group to identify early adopters and scope policies.
#!/bin/zsh
enrollmentStatus=$( /usr/bin/defaults read '/Library/Preferences/EarlyAdopter.plist' Enrolled )
echo "<result>$enrollmentStatus</result>"
@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 / Make new Outlook Address Book and Contact.applescript
Created July 23, 2020 21:28
Useful for when an admin needs to add a list of "safe" addresses to a user's Contacts but wants to keep them separate from the user's own contacts.
tell application "Microsoft Outlook"
make new address book in exchange account 1 with properties {name:"Company Contacts"}
make new contact with properties {first name:"Martin", last name:"Moose", email addresses:{{address:"mmoose@talkingmoose.net", type:work}, {address:"martin@aol.com", type:home}}} at address book "Company Contacts" of exchange account 1
end tell
@talkingmoose
talkingmoose / add-AD-user-data-to-Jamf-Pro.ps1
Last active March 11, 2022 04:02
Reads a pre-defined Advanced Computer Search and gets list of newly enrolled devices and their usernames. Looks up usernames in Active Directory and retrieves more user detail. Populates devices records with additional user in Jamf Pro.
# INSTRUCTIONS
# Create a folder on the Administrator Desktop named "Project"
# Run the script to generate the AES key
# Run the script to generate the Active Directory encrypted password file
# Run the script to generate the Jamf Pro encrypted password file
# Update the following variables:
# JamfProServer
@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)
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
@talkingmoose
talkingmoose / Another Rename Computer Script.bash
Last active December 23, 2021 21:18
Jamf, Catalina and osascript compatible. Prompts to choose a site and enter an asset tag before renaming the Mac and then updating Jamf Pro.
#!/bin/sh
# wait until the Dock process has started
while [[ "$setupProcess" = "" ]]
do
echo "Waiting for Dock"
setupProcess=$( /usr/bin/pgrep "Dock" )
sleep 3
done
@talkingmoose
talkingmoose / Download and Install Mozilla Firefox.zsh
Last active October 25, 2022 23:10
Downloads and installs the latest available Mozilla Firefox for Mac software directly on the client. This avoids having to manually download and store an up-to-date installer on a distribution server. Includes an optional checksum for added security.
#!/bin/zsh
:<<ABOUT_THIS_SCRIPT
-------------------------------------------------------------------------------
Written by:William Smith
Professional Services Engineer
Jamf
bill@talkingmoose.net
https://gist.github.com/b99a43948c4784631e9ad60eb714c776
@talkingmoose
talkingmoose / Match Version Number or Higher.bash
Last active May 6, 2024 20:13
Generates a regular expression (regex) that matches the provided version number or higher. Useful for Jamf Pro's "matches regex" operator in searches and smart groups where the results need to be the current version of an app or higher.
#!/bin/bash
<<ABOUT_THIS_SCRIPT
-------------------------------------------------------------------------------
Written by:William Smith
Professional Services Engineer
Jamf
bill@talkingmoose.net
https://gist.github.com/2cf20236e665fcd7ec41311d50c89c0e
@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 }' )