Skip to content

Instantly share code, notes, and snippets.

@gregneagle
gregneagle / fancy_defaults_read.py
Last active February 6, 2024 15:14
fancy_defaults_read.py: Reads a preference, prints its value, type, and where it is defined.
#!/usr/bin/python
import os
import sys
from CoreFoundation import (CFPreferencesAppValueIsForced,
CFPreferencesCopyAppValue,
CFPreferencesCopyValue,
kCFPreferencesAnyUser,
kCFPreferencesAnyHost,
@mrlesmithjr
mrlesmithjr / ansible-macos-homebrew-packages.yml
Last active July 18, 2024 20:59
Install MacOS Homebrew Packages With Ansible
---
- name: Install MacOS Packages
hosts: localhost
become: false
vars:
brew_cask_packages:
- atom
- docker
- dropbox
- firefox
@brysontyrrell
brysontyrrell / JamfUAPIAuthToken.py
Created October 19, 2016 17:52
Generate a token for the Jamf Universal API (UAPI) that will auto-refresh as needed.
import datetime
import logging
import requests
import urlparse
class JamfUAPIAuthToken(object):
def __init__(self, jamf_url, username, password):
"""
:param jamf_url: Jamf Pro URL
:type jamf_url: str
import base64
import getpass
import sys
import xml.etree.ElementTree as Et
import urllib
import urllib2
reload(sys)
sys.setdefaultencoding('utf-8')
@pudquick
pudquick / mount_shares_better.py
Last active January 19, 2023 22:07
Mounting shares in OS X using python and pyobjc - works with OS X 10.8+
import objc, CoreFoundation, Foundation
class attrdict(dict):
__getattr__ = dict.__getitem__
__setattr__ = dict.__setitem__
NetFS = attrdict()
# Can cheat and provide 'None' for the identifier, it'll just use frameworkPath instead
# scan_classes=False means only add the contents of this Framework
NetFS_bundle = objc.initFrameworkWrapper('NetFS', frameworkIdentifier=None, frameworkPath=objc.pathForFramework('NetFS.framework'), globals=NetFS, scan_classes=False)
@sheagcraig
sheagcraig / ThunderstrikeVulnerabilityEA.py
Last active August 29, 2015 14:25
ThunderstrikeVulnerabilityEA.py
#!/usr/bin/python
# Culled from https://gist.github.com/arubdesu/05b4172890450fa2d9e6
# Given a list of FW models and Thunderstrike patched FW versions,
# report on whether a machine has been patched.
import subprocess
import plistlib
@timsutton
timsutton / auto-update-mas-apps.sh
Last active March 7, 2018 06:54
Clear storeagent cache and trigger Mac App Store app updates.
#!/bin/sh
#
# Trigger an update of MAS (and softwareupdate) apps
#
# This seems to be all that's needed to schedule an immediate update of
# MAS apps. This should be run as a normal user. You can run this and
# tail the install log to get an idea of what's happening.
#
# You can also take a look at this user's ~/Library/Caches/com.apple.storagent
# directory to get a report on what apps were available, installable, etc.
@kbinani
kbinani / get_package_id.sh
Created July 24, 2013 14:29
Get package id from a *.pkg file (Mac OSX).
#!/bin/bash
function get_package_id { (
readonly PKG_INFO=PackageInfo
local PKG=$(cd "$(dirname "$1")"; pwd)/$(basename "$1")
local EXCLUDES=
for FILE in $(xar -t -f "$PKG" | grep -v $PKG_INFO); do
EXCLUDES="$EXCLUDES --exclude $FILE"
done
local TEMP=$(mktemp -t hoge | tr -d '\r')
@miguelgrinberg
miguelgrinberg / rest-server.py
Last active August 4, 2024 14:41
The code from my article on building RESTful web services with Python and the Flask microframework. See the article here: http://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask
#!flask/bin/python
from flask import Flask, jsonify, abort, request, make_response, url_for
from flask_httpauth import HTTPBasicAuth
app = Flask(__name__, static_url_path = "")
auth = HTTPBasicAuth()
@auth.get_password
def get_password(username):
if username == 'miguel':
@mathiasbynens
mathiasbynens / appify
Created November 12, 2010 13:46 — forked from subtleGradient/appify
appify — create the simplest possible Mac app from a shell script
#!/bin/bash
if [ "$1" = "-h" -o "$1" = "--help" -o -z "$1" ]; then cat <<EOF
appify v3.0.1 for Mac OS X - http://mths.be/appify
Creates the simplest possible Mac app from a shell script.
Appify takes a shell script as its first argument:
`basename "$0"` my-script.sh