Skip to content

Instantly share code, notes, and snippets.

View carlashley's full-sized avatar
🎯
Focusing on life.

Carl carlashley

🎯
Focusing on life.
View GitHub Profile
@carlashley
carlashley / apfs_disks.py
Last active January 20, 2018 23:11
Rough pythonisation of disktuil apfs -list -plist
#!/usr/bin/python
'''List APFS containers and return properties. Free to use/abuse/improve/laugh at'''
import plistlib
import subprocess
import sys
from collections import namedtuple
@carlashley
carlashley / darwin_env_var.sh
Last active March 30, 2023 17:07
Darwin Environment Variables
#!/bin/sh
# User path
/usr/bin/getconf DARWIN_USER_DIR
# Temp directory
# Note - $TMPDIR is the same as this
/usr/bin/getconf DARWIN_USER_TEMP_DIR
# Cache directory
@carlashley
carlashley / macOSInstaller_version.sh
Created July 26, 2017 02:19
Gets macOS X Installer app version.
#!/bin/sh
# Shamelessly stolen from https://loefflmann.blogspot.com.au/2015/03/finding-os-x-version-and-build-in-install-os-x-app.html
# Provide the path to the installer file from the command line.
if [[ ! -z $1 ]]; then
os_installer_path="$1"
echo "Attaching ${1}"
hdiutil attach "${os_installer_path}/Contents/SharedSupport/InstallESD.dmg" -quiet -noverify -nobrowse -mountpoint /Volumes/InstallESD.$$
hdiutil attach "/Volumes/InstallESD.$$/BaseSystem.dmg" -quiet -noverify -nobrowse -mountpoint /Volumes/BaseSystem.$$
@carlashley
carlashley / convert_config_profile.py
Last active March 16, 2023 22:23
Converts a Wi-Fi configuration profile from standard configuration to SystemConfiguration type
#!/usr/bin/python
'''Converts a standard Wi-Fi configuration profile for iOS/macOS that uses
a user certificate, and converts it into a SystemConfiguration profile type
that can be used to connect to a Wi-Fi network at macOS login screen.
This is useful where you need a laptop to be able to bind to an AD or LDAP
server, or just want to have user credential free Wi-Fi connection at the
system level.'''
import os
import plistlib
@carlashley
carlashley / active_interface.sh
Created February 6, 2017 22:22
Get the active interface for a given route
#!/bin/sh
# Get network interface. We sleep so that the interface has a chance to come up!
# Substitute the 0.0.0.0 address if you have a specific route that you want to test, however this may impact
# portability if a machine spends more time without access to that route than with.
# Give the interface a chance to come up - useful if this is used in any boot up processes
while [ $(route get 0.0.0.0 2>/dev/null | grep -c interface) != 1 ]; do
sleep 5
done
@carlashley
carlashley / diskInfo.py
Created December 22, 2016 01:03
Disk information in macOS
#!/usr/bin/python
# Function returns a dict containing the results of `diskutil info /dev/disk`
import plistlib
import subprocess
def disk_info(disk):
cmd = ['/usr/sbin/diskutil', 'info', '-plist', disk]
(results, error) = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
@carlashley
carlashley / hardware.py
Created December 21, 2016 03:39
Mac Hardware Info
#!/usr/bin/python
# Use system_profiler output in XML to get information about Mac hardware
import plistlib
import subprocess
cmd = ['system_profiler', '-xml', 'SPHardwareDataType']
(results, error) = subprocess.Popen(cmd,
@carlashley
carlashley / fix_promethean.sh
Created November 27, 2016 23:30
Fix issues with Promethean drivers & ActivInspire not running properly in Mac OS X El Capitan and macOS Sierra
#!/bin/sh
/bin/chmod -R 755 /usr/local/share/promethean
/bin/chmod -R 644 /Library/LaunchAgents/com.promethean.*
/bin/chmod -R 755 /usr/local/lib
@carlashley
carlashley / list_users.sh
Created November 25, 2016 10:47
List all local users and exclude system accounts and dump out as CSV
#!/bin/sh
# This will also work with /Search/Users instead of /Local/Users
/usr/bin/dscl localhost -list /Local/Users UniqueID | awk '$2 >= 100 { print $1 "," }' | grep -v "^_" > users.csv
@carlashley
carlashley / global_proxy.py
Last active November 14, 2016 10:52
Global proxies
#!/usr/bin/python
# A dictionary of detailed proxy information as seen in the Network system preference pane.
from SystemConfiguration import (
SCDynamicStoreCreate,
SCDynamicStoreCopyValue,
)
ds = SCDynamicStoreCreate(None, 'global_proxies', None, None)
result = SCDynamicStoreCopyValue(ds, 'State:/Network/Global/Proxies')