Skip to content

Instantly share code, notes, and snippets.

$ ./make_relocatable_python_framework.py --python-version 3.8.5
Downloading https://www.python.org/ftp/python/3.8.5/python-3.8.5-macosx10.9.pkg...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 28.8M 100 28.8M 0 0 6860k 0 0:00:04 0:00:04 --:--:-- 6860k
Expanding /var/folders/tc/sd4_mtvj14jdy7cg21m2gmcw000495/T/tmpdhiqv6m3...
Extracting /var/folders/tc/sd4_mtvj14jdy7cg21m2gmcw000495/T/tmpdhiqv6m3__expanded__/Python_Framework.pkg/Payload to ./Python.framework...
Ensuring correct modes for files in /Users/Shared/relocatable-python/Python.framework...
Analyzing /Users/Shared/relocatable-python/Python.framework...
...............................
@gregneagle
gregneagle / prefs_observer.py
Created August 1, 2017 18:20
Getting notified when a preference changes (using PyObjC)
from Foundation import NSObject, NSUserDefaults, NSKeyValueObservingOptionNew
from Foundation import NSRunLoop, NSDate
class PrefsObserver(NSObject):
def observe(self, domain, key):
self.domain = domain
self.key = key
if self:
self.defaults = NSUserDefaults.alloc().initWithSuiteName_(
from munkilib import gurl
def run_connection(options):
connection = gurl.Gurl.alloc().initWithOptions_(options)
percent_complete = -1
bytes_received = 0
connection.start()
try:
while not connection.isDone():
if connection.destination_path:
@gregneagle
gregneagle / gist:2c5b535c723aea5d3fc7
Last active January 7, 2018 19:45
Proper software version comparisons in Python
% python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> os_vers_1 = "10.9.5"
>>> os_vers_2 = "10.10"
>>> os_vers_2 > os_vers_1
False
>>> from distutils import version
>>> version.LooseVersion(os_vers_2) > version.LooseVersion(os_vers_1)
#!/usr/bin/python
import os
import pwd
from Foundation import CFPreferencesAppSynchronize
from Foundation import CFPreferencesSetValue
from Foundation import kCFPreferencesCurrentUser
from Foundation import kCFPreferencesCurrentHost
@gregneagle
gregneagle / munki_do.py
Created September 4, 2016 05:51
munki_do.py
#!/usr/bin/python
# encoding: utf-8
#
# Copyright 2009-2016 Greg Neagle.
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#!/usr/bin/python
import os
import subprocess
import sqlite3
desktop_picture_path = '/Library/Desktop Pictures/Wave.jpg'
database_location = os.path.expanduser(
'~/Library/Application Support/Dock/desktoppicture.db')
#!/usr/bin/python
import time
from Quartz import CGGetActiveDisplayList, CGGetOnlineDisplayList
from CoreFoundation import CFPreferencesCopyAppValue
def displayMirroringActive():
'''Returns True if any two displays are mirroring, False otherwise'''
@gregneagle
gregneagle / update_complex_pref_v1.py
Created January 26, 2015 20:06
Python scripts for MacTech MacEnterprise column "Managing Complex Preferences"
import CoreFoundation
from Foundation import NSDate
# read Safari's current ManagedPlugInPolicies
policy = CoreFoundation.CFPreferencesCopyAppValue(
'ManagedPlugInPolicies', 'com.apple.Safari')
if not 'com.oracle.java.JavaAppletPlugin' in policy:
# create an empty dict
policy['com.oracle.java.JavaAppletPlugin'] = {}
@gregneagle
gregneagle / gist:0774108ef15f345bd36c
Created February 19, 2015 16:31
VPN menu payload
<dict>
<key>PayloadContent</key>
<dict>
<key>com.apple.mcxMenuExtras</key>
<dict>
<key>Forced</key>
<array>
<dict>
<key>mcx_preference_settings</key>
<dict>