Skip to content

Instantly share code, notes, and snippets.

@gregneagle
gregneagle / fancy_defaults_read.py
Last active February 6, 2024 15:14
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,
@pudquick
pudquick / hi_groob.py
Created July 14, 2017 13:48
Search my gists ;p
#!/usr/bin/python
from Foundation import NSWorkspace, NSURL
import urllib
def show_gists():
NSWorkspace.sharedWorkspace().openURL_(NSURL.URLWithString_('https://gist.github.com/search?q=%40pudquick&ref=searchresults'))
def search_gists(search_string):
NSWorkspace.sharedWorkspace().openURL_(NSURL.URLWithString_('https://gist.github.com/search?q=%%40pudquick+%s&ref=searchresults' % search_string))
@pudquick
pudquick / psu_hack_2017.py
Created July 14, 2017 12:56
Locking the screen of my Mac and playing a sound file with pyObjC
#!/usr/bin/python
approved_UUIDs = ['your-beacon-UUID-here'] # see line 64
path_to_lock_sound = '/Users/frogor/Desktop/car_lock.m4a'
path_to_warn_sound = '/Users/frogor/Desktop/viper_warning.m4a'
import time
import objc
from objc import NO
from Foundation import NSBundle, NSClassFromString, NSObject, NSRunLoop, NSDate, NSUUID, NSMakeRange, NSURL
from AVFoundation import AVAudioPlayer
#!/usr/bin/python
# encoding: utf8
#
# Portions of code re-used from "makecatalogs" by Greg Neagle
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# Yo may obtain a copy of hte License at
#
# https://www.apache.org/licenses/LICENSE-2.0
@pudquick
pudquick / visible_apps.py
Created March 29, 2017 22:57
Getting the list of visible apps (think: Force Quit) in macOS via python and pyobjc
from Foundation import NSBundle
import objc
CoreServices = NSBundle.bundleWithIdentifier_('com.apple.CoreServices')
functions = [
('_LSCopyRunningApplicationArray', '@I'),
('_LSCopyApplicationInformation', '@I@@'),
]
constants = [
@joshua-d-miller
joshua-d-miller / 802.1x System Fix.py
Last active February 4, 2022 14:42
This script will allow your 802.1x Configuration Profile to work on any other Ethernet interface at the System Level
#!/usr/bin/python
# pylint: disable=E0611, E1101, E0602
''''Fix 802.1x When Using Config Profiles and PEAP-MSCHAPV2 or EAP-TLS'''
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# This script will find the system profile that is attached to one ethernet
# interface from our configuration profile and then copy it to all other
# ethernet interfaces so that other ethernet interfaces can be used instead
# of just the FirstActiveEthernet at time of profile installation. This issue
# is still an issue as of 10.12.3
@pudquick
pudquick / keychain_password.py
Created March 6, 2017 20:53
Storing and retrieving a generic password in the login.keychain in macOS via python and pyobjc
import objc
from ctypes import c_char
from Foundation import NSBundle
Security = NSBundle.bundleWithIdentifier_('com.apple.security')
S_functions = [
('SecKeychainGetTypeID', 'I'),
('SecKeychainItemGetTypeID', 'I'),
('SecKeychainAddGenericPassword', 'i^{OpaqueSecKeychainRef=}I*I*I*o^^{OpaqueSecKeychainItemRef}'),
('SecKeychainOpen', 'i*o^^{OpaqueSecKeychainRef}'),
@joshua-d-miller
joshua-d-miller / 802.1x Fix.py
Last active January 18, 2019 12:46
When deploying an EAP-TLS profile for 802.1x Ethernet, this script will create a User Identity preference which will allow a logged in user to use any Ethernet interface that is connected to their machine.
#!/usr/bin/python
# pylint: disable=C0103, W0612, E1101, E0602, E0611
# pylint: disable=W0101, W0110, W0141
''''Fix 802.1x When Using Config Profiles and EAP-TLS'''
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# This script will determine the profile ID that was used when
# installing the 802.1x Ethernet Identity preference and make
# a copy of the keychain entry to be used as a user identity preference
# so that any Ethernet can be used when a user is logged in. As of 10.12.3
@MagerValp
MagerValp / PyStrings.py
Created January 23, 2017 09:21
Find non-unicode strings in python 2 source.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
import sys
@pudquick
pudquick / battery.py
Last active April 20, 2023 06:06
Accessing battery details via python and pyobjc on macOS / OS X
import objc
from Foundation import NSBundle
IOKit = NSBundle.bundleWithIdentifier_('com.apple.framework.IOKit')
functions = [("IOServiceGetMatchingService", b"II@"),
("IOServiceMatching", b"@*"),
("IORegistryEntryCreateCFProperties", b"IIo^@@I"),
("IOPSCopyPowerSourcesByType", b"@I"),
("IOPSCopyPowerSourcesInfo", b"@"),