Skip to content

Instantly share code, notes, and snippets.

@pudquick
pudquick / beamsync.py
Last active September 28, 2023 15:16
#!/usr/bin/python
import ctypes, ctypes.util
# Import CoreGraphics as a C library, so we can call some private functions
c_CoreGraphics = ctypes.CDLL(ctypes.util.find_library('CoreGraphics'))
def disable_beam_sync(doDisable):
if doDisable:
# Disabling beam sync:
# 1st: Enable Quartz debug
@pmbuko
pmbuko / password_dialog.py
Last active August 29, 2015 14:11
Simple python example of a Pashua password prompt dialog with a checkbox to save the password. Requires Pashua.app and the Pashua.py connector in the same path.
#!/usr/bin/python
#
# Simple python example of a Pashua password prompt window with a checkbox
# for saving the password to the keychain. None of it is wired up to
# actually function. It's just an example of what you can do.
#
# For easiest testing, you should have the Pashua.py connector and Pashua.app
# in the same directory as this script.
#
# The test password is 'password'.
@trodemaster
trodemaster / gist:94ec1f1b24711a050634
Last active August 29, 2015 14:16
tools-rhel6-latest.sh
#!/bin/sh
# Install latest vmware tools from vmware.com repo for rhel 6
# get cert
wget -P /tmp http://packages.vmware.com/tools/keys/VMWARE-PACKAGING-GPG-RSA-KEY.pub
# install cert
sudo rpm --import /tmp/VMWARE-PACKAGING-GPG-RSA-KEY.pub
# Setup repo
@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
@bruienne
bruienne / gist:ec5205408b9e52bd5cfc
Last active June 7, 2024 19:59
Linux DMG/PKG notes
@bruienne
bruienne / modify_basesystem_dmg.py
Created April 8, 2015 03:27
Modify BaseSystem.dmg inside an InstallESD.dmg
#!/usr/bin/python
# modify_basesystem_dmg.py
#
# Adds additional frameworks to BaseSystem.dmg - Python is default
# Modify cpioextract() and xar_source to change what is extracted,
# and from what OS X installer PKG.
#
# To invoke:
#
# ./modify_basesystem_dmg.py /path/to/InstallESD.dmg
#!/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 / mount_shares.py
Last active March 7, 2021 16:27
Programmatically mount shares in OS X via python without the need for AppleScript
# This actually uses the same API call (NetFSMountURLSync) that AppleScript uses :D
# Note: As written, requires OS X 10.10+ / pyobjc 2.5.1+
import objc, CoreFoundation
from ctypes import c_void_p, pointer, cast
# The only reason I'm doing this the XML way is because I don't have a better way (yet)
# for correcting a function signature -after- it's already been imported.
# The problem is the last argument is a pointer to a CFArrayRef, which works out to a
# pointer to a pointer to a CFArray. pyobjc doesn't hadnle that much abstraction, so I created
@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)
@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 ]