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 / 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 / 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 / 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 / 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 / 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 / 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 / touristd.mobileconfig
Created September 28, 2017 03:44
touristd notification prompts in macOS High Sierra
<?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>PayloadContent</key>
<array>
<dict>
<key>PayloadContent</key>
<dict>
<key>com.apple.touristd</key>
@carlashley
carlashley / import_ova.sh
Last active October 6, 2017 03:17
Imports a VirtualBox OVA for currently logged in user.
#!/bin/sh
# This will import a VirtualBox OVA file for the currently logged in user; by default, when `VBoxManage import` is run in
# root environment, it will import the VM into a folder in the root user home directory.
# Handy for enabling self-service installs of a VM.
# The script is _very_ basic and doesn't have any form of version management/removal/upgrade capability, but this
# should be relatively easily expandable with the right `VBoxManage` commands.
#
# This example is for use in a package that doesn't actually install the OVA on disk, but imports it direct from the .pkg
# file. Essentially 'payload free', but not ;)
@carlashley
carlashley / current_user.py
Last active August 25, 2021 04:56
Returns a named tuple containing information about current logged in user.
#!/usr/bin/env python3
"""Current user logged into macOS, shamelessly stealing macmule's get current
logged in user from https://macmule.com/2014/11/19/how-to-get-the-currently-logged-in-user-in-a-more-apple-approved-way/"""
import pwd
import sys
from collections import namedtuple
try:
from SystemConfiguration import SCDynamicStoreCopyConsoleUser
@carlashley
carlashley / codesign.example
Last active March 25, 2022 20:41
Code Signing Scripts on macOS
#Find valid code signing certificates with:
#/usr/bin/security find-identity -p codesigning -v
#Eg:
#[carl@pegasus]:outset # security find-identity -p codesigning -v
# 1) A898234JHSDFH38WERKHJSDFLJ2UY4092367HJK9H4J18 "Mac Developer: [email protected] (ABC01FFFGH)"
# 1 valid identities found
#Code Sign file with:
#/usr/bin/codesign -s "Mac Developer: [email protected] (ABC01FFFGH)" -i <bundleID> <file>