Skip to content

Instantly share code, notes, and snippets.

@brandonb927
brandonb927 / osx-for-hackers.sh
Last active May 2, 2024 03:13
OSX for Hackers: Yosemite/El Capitan Edition. This script tries not to be *too* opinionated and any major changes to your system require a prompt. You've been warned.
#!/bin/sh
###
# SOME COMMANDS WILL NOT WORK ON macOS (Sierra or newer)
# For Sierra or newer, see https://github.com/mathiasbynens/dotfiles/blob/master/.macos
###
# Alot of these configs have been taken from the various places
# on the web, most from here
# https://github.com/mathiasbynens/dotfiles/blob/5b3c8418ed42d93af2e647dc9d122f25cc034871/.osx
@gregneagle
gregneagle / NSPredicateTester.py
Last active June 14, 2023 21:47
NSPredicateTester.py
#!/usr/local/munki/munki-python
import sys
import os
from Foundation import NSDate
from Foundation import NSPredicate
def doComparison(comp_string, obj):
print('Comparison: %s' % comp_string)
#!/usr/bin/python
# As written, this requires the following:
# - OS X 10.6+ (may not work in 10.10, haven't tested)
# - python 2.6 or 2.7 (for collections.namedtuple usage, should be fine as default python in 10.6 is 2.6)
# - pyObjC (as such, recommended to be used with native OS X python install)
# Only tested and confirmed to work against 10.9.5
# Run with root
#!/usr/bin/python3
'''
Display CPU usage for a given process
emoji ref: https://github.com/sheagcraig/Spruce/blob/master/spruce.py
'''
import subprocess
import time
import argparse
@pudquick
pudquick / spotlight_exclusions.py
Last active April 27, 2022 16:47
List and control Spotlight exclusions in OS X via python and pyobjc on OS X 10.11
# Only tested on OSX 10.11.5
import objc
from Foundation import NSBundle
Metadata_bundle = NSBundle.bundleWithIdentifier_('com.apple.Metadata')
functions = [
('_MDCopyExclusionList', b'@'),
('_MDSetExclusion', b'@@I'),
]
@sheagcraig
sheagcraig / AdwareCheckExtensionAttribute.py
Last active November 27, 2021 23:51
Check for Adware per Apple Kbase article
#!/usr/bin/python
"""Identify or remove files known to be involved in Adware/Malware
infection.
Most of the code applies to building a list of malware files. Thus,
both extension attribute and removal handling are included.
Cleans files as a Casper script policy; thus, it expects four total
arguments, the first three of which it doesn't use, followed by
--remove
@bruienne
bruienne / getosversionfromdmg.py
Last active April 16, 2021 05:29
Get OS X version from DMG
#!/usr/bin/python
#
# getosversionfromdmg.py
#
# Copyright (c) 2014 The Regents of the University of Michigan
#
# Retrieves the OS version and build from the InstallESD.dmg contained in
# a typical "Install (Mac) OS X <Name>.app" bundle.
#
# To run:
@gregneagle
gregneagle / gist:01c99322cf985e771827
Created January 20, 2015 18:16
Using CFPreferences in Python to set a complex preference
import plistlib
import CoreFoundation
from Foundation import NSDate, NSMutableArray, NSMutableDictionary
# read the current ManagedPlugInPolicies
policy = CoreFoundation.CFPreferencesCopyAppValue("ManagedPlugInPolicies", "com.apple.Safari")
if policy:
# policy is an immutable dict, so we have to make a mutable copy
my_policy = NSMutableDictionary.alloc().initWithDictionary_copyItems_(policy, True)
@homebysix
homebysix / shard.sh
Last active February 1, 2021 23:44
shard.sh
#!/bin/bash
###
#
# Name: shard.sh
# Description: This Casper extension attribute takes a Mac serial
# number as input and uses that serial number to output a
# number from 0 to 9. This can be useful in scoping Casper
# policies to a specific percentage of the fleet.
# Author: Elliot Jordan <elliot@elliotjordan.com>
#!/usr/bin/python
#
# list_unused_munki_pkgs.py
# Tim Sutton
#
# Simple script to list all Munki pkgs not currently referenced in a specific list
# of catalogs.
# It does not delete anything.
#
# CATALOGS can be modified to a list of catalogs in your repo that should be indexed.