Skip to content

Instantly share code, notes, and snippets.

@gregneagle
gregneagle / com.foo.displaymirroring.plist
Last active December 18, 2015 03:59
A Python/PyObjC port of Fabian Canas's command-line mirror tool from http://mirror-displays.googlecode.com/. Demonstrates use of the Quartz Display Services to control display mirroring, and also shows how PyObjC handles "pass-by-reference" parameters. The LaunchAgent plist defines a job that runs at the loginwindow, running mirrortool.py to ena…
<?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>Disabled</key>
<false/>
<key>Label</key>
<string>com.foo.displaymirroring</string>
<key>LimitLoadToSessionType</key>
<array>
@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
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')
@gregneagle
gregneagle / gist:6957826
Last active January 4, 2021 09:39
Using PyObjC and NSWorkspace to set the desktop picture. I am such a hypocrite!
#!/usr/bin/python
'''Uses Cocoa classes via PyObjC to set a random desktop picture on all screens.
Tested on Mountain Lion and Mavericks.
See:
https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSWorkspace_Class/Reference/Reference.html
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html
@gregneagle
gregneagle / MavericksAppStore.mobileconfig
Last active December 26, 2015 13:49
Profile to require user to be an admin to install items (including software updates) from the App Store
<?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>PayloadContent</key>
<array>
<dict>
<key>PayloadType</key>
<string>com.apple.appstore</string>
<key>PayloadVersion</key>
import httplib
import re
import socket
import sys
import urllib2
import ssl
class InvalidCertificateException(httplib.HTTPException, urllib2.URLError):
def __init__(self, host, cert, reason):
httplib.HTTPException.__init__(self)
@gregneagle
gregneagle / gurl.py
Last active December 28, 2015 22:29
# http://httpstat.us - for test error codes
# http://uri-labs.com/macosx_headers/NSURLConnection_h/Protocols/NSURLConnectionDelegate/index.html
# Notes:
# - Errors are only thrown when the connection:
# - Is interrupted before the headers can complete
# - SSL couldn't happen correctly
# - The connection never happens
# - A delegate.response always has a NSHTTPURLResponse key for HTTP/HTTPS
# For a file:// transfer, it's NSURLResponse
@gregneagle
gregneagle / finish_jenkins_autopkg_run.py
Created January 3, 2014 19:00
Some scripts from my MacSysAdmin 2013 demo
#!/usr/bin/env python
# encoding: utf-8
"""
finish_jenkins_autopkg_run.py
Created by Greg Neagle on 2013-08-23.
"""
import os
import plistlib
<key>Input</key>
<dict>
<key>NAME</key>
<string>Adium</string>
<key>MUNKI_REPO_SUBDIR</key>
<string>apps</string>
<key>pkginfo</key>
<dict>
<key>catalogs</key>
<array>
% autopkg info Firefox_RC.munki
Description: Downloads Firefox disk image and imports into Munki.
Values for FIREFOX_BUILD correspond to directories here: http://download-origin.cdn.mozilla.net/pub/mozilla.org/firefox/releases/
Some useful values are: 'latest', 'latest-10.0esr', 'latest-esr', 'latest-3.6', 'latest-beta'
LOCALE corresponds to directories at http://download-origin.cdn.mozilla.net/pub/mozilla.org/firefox/releases/$FIREFOX_BUILD/mac/
Examples include 'en-US', 'de', 'ja-JP-mac', 'sv-SE', and 'zh-TW'
No idea if all Firefox builds are available in all the same localizations, so you may need to verify that any particular
combination is offered.
Identifier: com.disneyanimation.firefox-RC
Munki import recipe: True