Skip to content

Instantly share code, notes, and snippets.

@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 / 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):
#!/bin/bash
#
# Script: Safely Close Application
#
# Description:
# Safely closes and application after alerting user and prompting to save
# any unsaved documents (if applicable).
#
# Parameters:
# - app_name: Name of the application
@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
@haircut
haircut / Quit-All-Apps-With-Whitelist.sh
Created February 8, 2017 15:16
Closes all running apps, excluding those found in a customizable whitelist
#!/bin/sh
# Quit apps command
read -r -d '' OSASCRIPT_COMMAND <<EOD
set white_list to {"Finder"}
tell application "Finder"
set process_list to the name of every process whose visible is true
end tell
repeat with i from 1 to (number of items in process_list)
set this_process to item i of the process_list
#!/bin/bash
#####################################
#
# Keychain Repair
#
# Removes a User's login keychain, creates a new login keychain, sets it
# as the default keychain, deletes any Local Items keychain folders,
# then reboots the system interactively
#
# University of North Carolina Asheville ITS
@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>
<PrinterDefinitions>
<Printer>
<Name>Example Printer</Name>
<Server>print.org.edu</Server>
<ShareName>ExamplePrinter</ShareName>
<SMBURI>smb://print.org.edu/ExamplePrinter</SMBURI>
<LPDURI>lpd://print.org.edu/ExamplePrinter</LPDURI>
<Location>Lobby</Location>
<Option>option_one=value</Option>
<Option>second_opt=something</Option>