Skip to content

Instantly share code, notes, and snippets.

View matthewbodaly's full-sized avatar

Matthew matthewbodaly

View GitHub Profile
@opragel
opragel / google_drivefs_update_checker.py
Last active October 4, 2017 22:55 — forked from bruienne/google_chrome_update_checker.py
Fork of Chrome update query for DriveFS
#!/usr/bin/python
import xml.etree.ElementTree as ET
import requests
import uuid
params = {'cup2hreq': 'foo', 'cup2key': 'bar'}
platform = 'mac'
os_version = '10.12'
@pudquick
pudquick / autotimezone.py
Last active February 11, 2020 15:55
Forcing automatic timezone discovery with pyobjc on OS X
# Tested on 10.11
# Assumes your network is in a state to actually do the discovery and that you have
# automatic timezone discovery enabled in Date & Time and Location services enabled
# (Generally this means wifi enabled on your device and network stack is up)
# For enabling location services and auto, check Allister's work here:
# https://gist.github.com/arubdesu/b72585771a9f606ad800
from Foundation import NSBundle
TZPP = NSBundle.bundleWithPath_("/System/Library/PreferencePanes/DateAndTime.prefPane/Contents/Resources/TimeZone.prefPane")
@rdewolff
rdewolff / GIF-Screencast-OSX.md
Created June 30, 2016 10:21 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@pudquick
pudquick / lockscreen_pyobjc.py
Created June 15, 2016 17:14
Locking the screen immediately with pyobjc
import objc
from Foundation import NSBundle
login_bundle = NSBundle.bundleWithPath_('/System/Library/PrivateFrameworks/login.framework')
functions = [('SACLockScreenImmediate', '@'),]
objc.loadBundleFunctions(login_bundle, globals(), functions)
# Lock the screen regardless of security settings or who is logged in
result = SACLockScreenImmediate()
@pudquick
pudquick / fastuser_logincheck.py
Created April 26, 2016 05:39
Using CGSSessionCopyAllSessionProperties to detect logged-in users the way the Fast User switching menu extra does on OS X with python and pyobjc
import objc
from Foundation import NSBundle
CG_bundle = NSBundle.bundleWithIdentifier_('com.apple.CoreGraphics')
functions = [("CGSSessionCopyAllSessionProperties", b"@"),]
objc.loadBundleFunctions(CG_bundle, globals(), functions)
# example usage: graphical_security_sessions = CGSSessionCopyAllSessionProperties()
@pudquick
pudquick / fav_servers.py
Created February 14, 2016 02:16
Modifying the Favorite Servers list (in Finder's "Connect to Server" dialog) on OS X 10.11, a revisit of my blog post at: http://michaellynn.github.io/2015/10/24/apples-bookmarkdata-exposed/
import os.path
from Foundation import NSData, NSKeyedUnarchiver, SFLListItem, NSURL, NSMutableDictionary, NSKeyedArchiver, NSString, NSDictionary, NSArray
def load_favservers(sfl_path):
if os.path.isfile(sfl_path):
# File exists, use it
sfl_decoded = NSKeyedUnarchiver.unarchiveObjectWithData_(NSData.dataWithContentsOfFile_(sfl_path))
else:
# File doesn't exist, make a blank template
sfl_decoded = {u'items': [],
@pudquick
pudquick / ProgressDialog.py
Created August 27, 2015 07:35
This is python for a portable, self-contained class called "ProgressDialog" which allows you to create a Cocoa progress indicator dialog for OS X while you do things in a script. Enjoy.
class ProgressDialog(object):
def __init__(self, message, title, use_bar=True):
super(self.__class__, self).__init__()
self.message = message
self.title = title
self.use_bar = use_bar
self.queue = None
self.process = None
def display(self):
# [ begin black magic ]
@pudquick
pudquick / reorder_wifi.py
Last active July 16, 2022 01:03
This python code uses Objective-C calls to reorder pre-existing SSIDs in your WiFi interfaces to place a preferred SSID at the top (without removing / re-adding)
#!/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
@pudquick
pudquick / http_flatpkg_pkginfo.py
Created May 11, 2014 07:13
This python project is able to retrieve the PackageInfo metadata from flatpkg files over HTTP without downloading the entire .pkg file (if the web server it's hosted on supports partial file transfer / byte ranges)
# Skip to the end to see what this can do.
#
# http://s.sudre.free.fr/Stuff/Ivanhoe/FLAT.html
# Flat packages are xar files with a particular structure
# We're looking for the PackageInfo file within the xar file
import urllib2, ctypes, zlib
import xml.etree.ElementTree as ET
class SimpleObj(object):
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active May 2, 2024 05:55
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application: