Skip to content

Instantly share code, notes, and snippets.

@haircut
haircut / run_jamf_policy.py
Last active July 31, 2018 02:25
Utility function to run a Jamf Pro policy
# encoding: utf-8
import subprocess
def run_jamf_policy(p):
"""Runs a jamf policy by id or event name"""
cmd = ['/usr/local/bin/jamf', 'policy']
if isinstance(p, basestring):
@haircut
haircut / com.apple.Safari.plist
Last active February 7, 2018 16:06
Disables adding common "Internet Accounts", disables auto-open of "Safe" downloads, disables all form autofill
<?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>AutoOpenSafeDownloads</key>
<false/>
<key>DomainsToNeverSetUp</key>
<array>
<string>aol.com</string>
<string>facebook.com</string>
@haircut
haircut / opendirectoryd_version.py
Created November 30, 2017 14:19
Check the project build version of opendirectoryd to confirm Security Update 2017-001 is installed
import subprocess
factoid = 'opendirectoryd_version'
def fact():
'''
Returns the "project version" number used to build opendirectoryd
per https://support.apple.com/en-gb/HT208315 to check that
"Security Update 2017-001" is installed
'''
#!/bin/bash
# modified from original by Rich Trouton
# https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/block_root_account_login
ERROR=0
# Set root password to some uuid, eg. 1730DFA3-C59B-447C-BAE8-3C3F052862A4
rootpassword=$(uuidgen)
@haircut
haircut / audit-logins.py
Last active November 26, 2017 16:08
Auditing login events on macOS
#!/usr/bin/python
@haircut
haircut / getusers.py
Last active November 7, 2017 03:57
get a list of all non-system users on a Mac in Python
def getusers():
'''get all non-system users on this Mac'''
cmd = ['dscl', '.', '-list', '/Users']
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, _ = proc.communicate()
userlist = out.splitlines()
users = []
filter_out = ['daemon', 'root', 'nobody']
for user in userlist:
if not user.startswith('_') and not user in filter_out:
@haircut
haircut / jamf-pro-script-environment.py
Last active June 27, 2017 14:46
Determine the Execution Environment of a Jamf Pro script
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Jamf Pro - Determine Execution Environment
"""
import os
def is_running_directly():
"""
@haircut
haircut / execute-as-user-example.py
Created May 5, 2017 17:14
From @Elios on macadmins#python
#!/usr/bin/python
import os
import pwd
from Foundation import CFPreferencesAppSynchronize
from Foundation import CFPreferencesSetValue
from Foundation import kCFPreferencesCurrentUser
from Foundation import kCFPreferencesCurrentHost
@haircut
haircut / remove-false-google-docs-g-suite-tokens.sh
Last active May 4, 2017 01:00
Thanks to @chadnielsen on macadmins#g-suite - Comment out line 39 to audit rather than remove
#!/bin/bash
# Scan and Remove False Google Docs Tokens
# Assumes GAM is installed. Change the path if you need to.
###################################[ VARIABLE DEFINITIONS ]##################################
#set -x
runINT="3600" #seconds
runDATE=$(date +%d-%m-%Y-%H-%M)
@haircut
haircut / clear-saved-printer-passwords.sh
Created February 12, 2017 03:16
Removes keychain entries in the logged-in-user's login keychain related to campus print servers. Useful after password changes.
#!/bin/bash
###
#
# Name: clear-saved-printer-passwords.sh
# Description: Removes keychain entries in the logged-in-user's login keychain
# related to campus print servers. Useful after password changes.
# Author: Matthew Warren <bmwarren@unca.edu>
# Created: 2015-08-15
# Last Modified: 2017-02-11