Skip to content

Instantly share code, notes, and snippets.

@pudquick
pudquick / secure_gurl.py
Last active September 30, 2016 14:43
Security automation for ca.pem + client.pem
"""
First attempt at bringing security into play with the .pem files.
Only the security tool is used, no additional tools (openssl, etc.).
This code does the following:
- Creates the specified keychain if it doesn't exist
- Unlocks it with the specified password
- Configures it to not lock
- Adds it to the keychain search paths if it's not present already (necessary for 10.9)
- Import the client.pem cert / identity
@pudquick
pudquick / mtv.py
Last active December 29, 2015 18:59
import re, requests, HTMLParser, os, pipes
from xml.dom.minidom import parseString
global all_series
def process_show_list(show_list):
split_boundary = '<li class="group">'
show_name = r'meta content="([^"]+)" itemprop="name"'
show_url = r'<a itemprop="" href="([^"]+)">'
found_shows = set()
@pudquick
pudquick / mas_updates.py
Last active January 25, 2024 15:47
Mac App Store updates
# App Store playing
import urllib, urllib2, json, plistlib
###
# Utility function for performing an iTunes-style search
def perform_itunes_search(api_url, query_list=[]):
query_str = urllib.urlencode(query_list)
response_handle = urllib2.urlopen('https://itunes.apple.com/%s?%s' % (api_url, query_str))
def match_dict(list_of_dicts_to_search, matching_dict):
for a_dict in list_of_dicts_to_search:
if all(map(lambda x: a_dict.get(x[0], None) == x[1], matching_dict.items())):
return a_dict
return None
@pudquick
pudquick / gist:8307185
Last active July 5, 2016 13:18
Workflow for editing the index.xml in a iBooks Author .iba file without issues
@pudquick
pudquick / notify.py
Last active September 3, 2023 16:51
Notification in pyobjc
# Banner-style (default)
from Foundation import NSUserNotification, NSUserNotificationCenter
def notify(title, subtitle, text):
notification = NSUserNotification.alloc().init()
notification.setTitle_(str(title))
notification.setSubtitle_(str(subtitle))
notification.setInformativeText_(str(text))
notification.setSoundName_("NSUserNotificationDefaultSoundName")
NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
<?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>allow-root</key>
<true/>
<key>authenticate-user</key>
<true/>
<key>class</key>
<string>user</string>
@pudquick
pudquick / picture_folders.py
Last active September 26, 2019 20:25
Modify the per-user picture folders suggested in "Desktop & Screen Savers"
from CoreFoundation import CFPreferencesCopyAppValue, CFPreferencesSetAppValue, CFPropertyListCreateDeepCopy, kCFPropertyListMutableContainersAndLeaves, CFPreferencesAppSynchronize
folder_to_add = u'/Abosulte/Path/To/Folder'
desktop_settings = CFPreferencesCopyAppValue('DSKDesktopPrefPane', 'com.apple.systempreferences') or dict()
mutable_desktop_settings = CFPropertyListCreateDeepCopy(None, desktop_settings, kCFPropertyListMutableContainersAndLeaves)
folder_paths = mutable_desktop_settings.get('UserFolderPaths', list())
@pudquick
pudquick / pids.py
Last active September 19, 2022 21:06
Get pids and path executables for processes running on OS X in python
from ctypes import CDLL, sizeof, memset, c_uint32, create_string_buffer
MAXPATHLEN = 1024
PROC_PIDPATHINFO_MAXSIZE = MAXPATHLEN*4
PROC_ALL_PIDS = 1
libc = CDLL('libc.dylib')
def get_pids():
number_of_pids = libc.proc_listpids(PROC_ALL_PIDS, 0, None, 0)
pid_list = (c_uint32 * (number_of_pids * 2))()
@pudquick
pudquick / keymaster.py
Last active May 26, 2020 15:13
Pythonic in-depth control of the user keychain domain
import os.path, base64
from ctypes import CDLL, Structure, POINTER, byref, addressof, create_string_buffer, c_int, c_uint, c_ubyte, c_void_p, c_size_t
from CoreFoundation import kCFStringEncodingUTF8
# Wheee!
Security = CDLL('/System/Library/Frameworks/Security.Framework/Versions/Current/Security')
# I don't use the pyObjC CoreFoundation import because it attempts to bridge between CF, NS, and python.
# When you try to mix it with Security.Foundation (pure C / CF), you get nasty results.
# So I directly import CoreFoundation to work with CFTypes to keep it pure of NS/python bridges.
CFoundation = CDLL('/System/Library/Frameworks/CoreFoundation.Framework/Versions/Current/CoreFoundation')