Skip to content

Instantly share code, notes, and snippets.

View AndrewWCarson's full-sized avatar
🐦

Andrew Worth Carson AndrewWCarson

🐦
View GitHub Profile
@AndrewWCarson
AndrewWCarson / bacon.sh
Created May 28, 2019 16:20
The narwhal bacons at midnight.
#!/bin/bash
(while sleep 30; do osascript -e 'set Volume 2' && say bacon; done) &
@AndrewWCarson
AndrewWCarson / Location.py
Created May 28, 2019 15:35
Outputs the latitude and longitude if Python has access to macOS Location Services.
#!/usr/bin/python
import CoreLocation
CLValidAuth = [CoreLocation.kCLAuthorizationStatusAuthorized]
def locationServicesEnabled():
if CoreLocation.CLLocationManager.locationServicesEnabled():
return True
else:
@AndrewWCarson
AndrewWCarson / Install All System Updates.sh
Last active May 20, 2019 20:17
Applies any available updates and prompts any logged-in user to restart.
#!/bin/bash
# Modify these strings to change the verbiage in the badge notification.
title="Updates Applied"
description="macOS updates have been applied to your device. Please restart to complete the process."
acceptText="Restart"
closeText="Later"
if (( $(softwareupdate -l 2>&1 | grep -c ' *') > 0 )); then
softwareupdate -ia
@AndrewWCarson
AndrewWCarson / 32-Bit Apps.py
Created May 20, 2019 17:27
Prints all apps that are 32-bit only.
#!/usr/bin/python
import subprocess
import plistlib
def get32BitApps():
cmd = '/usr/sbin/system_profiler -xml SPApplicationsDataType'
p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if p.returncode != 0:
@AndrewWCarson
AndrewWCarson / Location Services Enabled.py
Last active May 10, 2019 21:33
Returns True/False string for use detecting if Location Services is turned on.
#!/usr/bin/python
import CoreLocation
def locationServicesEnabled():
if CoreLocation.CLLocationManager.locationServicesEnabled():
return True
else:
return False
@AndrewWCarson
AndrewWCarson / Check For Kext Whitelist.sh
Last active April 25, 2019 18:11
Snippet for checking kernel extension whitelisting.
KEXT_TEAM_ID="ABCDEFG"
majorVersion=$(sw_vers -productVersion | awk -F. '{print $2}')
minorVersion=$(sw_vers -productVersion | awk -F. '{print $3}')
echo "Major macOS version: $majorVersion"
echo "Minor macOS version: $minorVersion"
if (( majorVersion > 13 )) || (( majorVersion == 13 && minorVersion > 2 )); then
if ! /usr/bin/sqlite3 /var/db/SystemPolicyConfiguration/KextPolicy "SELECT team_id FROM kext_policy_mdm;" | /usr/bin/grep "$KEXT_TEAM_ID"; then
echo 'Kernel extension not whitelisted.'
exit 1
@AndrewWCarson
AndrewWCarson / Toggle macOS Theme.py
Created March 29, 2019 23:05
Toggle between Light & Dark mode.
#!/usr/bin/python
#
# This toggles the macOS appearance from Light mode to Dark mode and vice
# versa.
#
# Big thanks to Mike Lynn for his help. Esp. this gist:
# https://gist.github.com/pudquick/ba235b7e90aafb9986158697a457a0d0
#
# Still looking for the function to perfectly simulate changing themes via the
# System Prefs UI. iStat menus seems to not be getting the hint.
@AndrewWCarson
AndrewWCarson / Has SSD.py
Created March 28, 2019 21:01
Uses pyobjc and IOKit to check for the BootDriveIsInternalSolidState value.
#!/usr/bin/python
# Based on some nice gists by Mike Lynn (@pudquick)
import objc
from CoreFoundation import NSBundle
IOKit_bundle = NSBundle.bundleWithIdentifier_('com.apple.framework.IOKit')
functions = [("IOServiceGetMatchingService", b"II@"),
@AndrewWCarson
AndrewWCarson / Set Light Mode.sh
Created March 25, 2019 22:11
Changes the macOS theme to Light mode in Mojave.
#!/bin/bash
# This requires the parent process to have "System Events" enabled in TCC. When
# running this from Addigy, /Library/Addigy/go-agent will need that
# whitelist.
username=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");')
# Do nothing if no one logged in.
if [[ "$username" != "" ]]; then
# Tell "System Events" to change to light mode.
@AndrewWCarson
AndrewWCarson / Is VM.py
Last active February 12, 2019 15:08 — forked from pudquick/macvm_detect.py
Addigy boolean Custom Fact that detects whether the machine is a VM based on a script from Mike Lynn <3.
#!/bin/python
from ctypes import CDLL, c_uint, byref, create_string_buffer
libc = CDLL('/usr/lib/libc.dylib')
def sysctl(name):
size = c_uint(0)
libc.sysctlbyname(name, None, byref(size), None, 0)
buf = create_string_buffer(size.value)
libc.sysctlbyname(name, buf, byref(size), None, 0)