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,
@mrik23
mrik23 / MSOL-BulkRemoveDirectAssignedLicense.ps1
Last active June 7, 2023 04:23
Remove in bulk direct assigned license to users who have group assigned license with Azure AD PowerShell v1
<#
Modified version of the script from Microsoft Documentation.
Removed the part that checks if the users is assigned more products than the group assigned license.
Added connection part and help to find Sku and Group Object ID.
This script requires Azure AD (aks MSOL) PowerShell v1. It doesn't seem possible to do so with v2.
Ref: https://docs.microsoft.com/en-us/azure/active-directory/active-directory-licensing-ps-examples
#>
Import-Module MSOnline
$UserCredential = Get-Credential
parse_array() {
FS=':'
key=(); val=()
for (( i=0 ; i < $(eval echo \${#$1[@]}) ; i++ )); do
key+=( "$(eval echo \${$1[$i]} | awk -F${FS} '{print $1}')" )
val+=( "$(eval echo \${$1[$i]} | awk -F${FS} '{print $2}')" )
done
}
# Assuming script contains myarray=( "key1:value1" "key2:value2" )
parse_array myarray
@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 = [
@sheagcraig
sheagcraig / uninstall_office2016.py
Created September 26, 2016 15:05
Silent Uninstall of Office 2016
#!/usr/bin/python
# Completely uninstall Office 2016, as per:
# https://support.office.com/en-us/article/Uninstall-Office-2016-for-Mac-eefa1199-5b58-43af-8a3d-b73dc1a8cae3
# and
# https://support.office.com/en-us/article/Troubleshoot-Office-2016-for-Mac-issues-by-completely-uninstalling-before-you-reinstall-ec3aa66e-6a76-451f-9d35-cba2e14e94c0?ui=en-US&rs=en-US&ad=US
import glob
import os
'''Routines for manipulating the Dock'''
import os
import subprocess
from Foundation import NSURL
from Foundation import CFPreferencesAppSynchronize
from Foundation import CFPreferencesCopyAppValue
from Foundation import CFPreferencesSetAppValue
@pudquick
pudquick / measure.py
Last active February 8, 2023 16:05
Get a sorted descriptive json output of hashes for a directory, suitable for diffing
#!/usr/bin/env python3
import os, os.path, json, hashlib, subprocess, argparse, sys, stat
BUFFER_SIZE = 65536
def checksum_directory(source_path, progress=False):
filesystem_details = dict()
# rough guess of how many files are in a directory
# horrible hack with a little fudge
if not os.path.isdir(source_path):
@opragel
opragel / ea_get_chrome_extensions.py
Last active January 11, 2018 22:38
ea_get_chrome_extensions.py
#!/usr/bin/python
## Script: get_chrome_extensions.py
## Author: Christopher Collins (christophercollins@livenation.com)
# also, owen wuz here. minor corrections (utf-8)
###########################################
##Description: This script searches the last logged in user's installed extensions and submits it to Casper during an inventory report.
###########################################
import os
@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 / warranty_update.py
Last active March 10, 2019 11:49
Casper warranty estimation, stored locally at /Library/Preferences/com.apple.warranty - in python!
#!/usr/bin/python
import os.path, subprocess, datetime, dateutil.parser, time, sys
def apple_year_offset(dateobj, years=0):
# Convert to a maleable format
mod_time = dateobj.timetuple()
# Offset year by number of years
mod_time = time.struct_time(tuple([mod_time[0]+years]) + mod_time[1:])
# Convert back to a datetime obj
return datetime.datetime.fromtimestamp(int(time.mktime(mod_time)))