Skip to content

Instantly share code, notes, and snippets.

@gregneagle
gregneagle / gist:2c5b535c723aea5d3fc7
Last active December 5, 2024 10:42
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)
@gregneagle
gregneagle / gist:9c684ed9366bc12091da
Last active December 5, 2024 10:42
Notes on getting Project iMAS MDM Server running under virtualenv on OS X
See https://github.com/project-imas/mdm-server#setup for starting point.
Assuming you have virtualenv installed....
bash-3.2$ virtualenv mdm-server-env
New python executable in mdm-server-env/bin/python
Installing setuptools, pip...cd mdone.
bash-3.2$ cd mdm-server-env/
bash-3.2$ source bin/activate
(mdm-server-env)bash-3.2$ easy_install web.py
% curl -s http://www.getmacapps.com/raw/3
#!/bin/bash
mkdir ~/getmacapps_temp
cd ~/getmacapps_temp
# Installing Chrome
curl -L -O "https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg"
hdiutil mount -nobrowse googlechrome.dmg
cp -R "/Volumes/Google Chrome/Google Chrome.app" /Applications
@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
'''Routines for manipulating the Dock'''
import os
import subprocess
from Foundation import NSURL
from Foundation import CFPreferencesAppSynchronize
from Foundation import CFPreferencesCopyAppValue
from Foundation import CFPreferencesSetAppValue
#!/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 / sysctl_demo.py
Last active December 5, 2024 10:39
Based on sysctl function by Michael Lynn aka frogor aka pudquick aka ????
# Based on sysctl function by Michael Lynn
# https://gist.github.com/pudquick/581a71425439f2cf8f09
from ctypes import CDLL, c_uint, byref, create_string_buffer
from ctypes import cast, POINTER, c_int32, c_int64
from ctypes.util import find_library
import struct
libc = CDLL(find_library('c'))
#!/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 / fancy_defaults_read.py
Last active December 5, 2024 10:38
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,
@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_(