Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Stephen Warneford-Bygrave wegotoeleven

🎯
Focusing
View GitHub Profile
View usefulVariables.md

In packages

  • $0 Script path
  • $1 Package path
  • $2 Default location
  • $3 Target volume

Miscellaneous

  • INSTALL_DIR=$(dirname $0)
View loggingCommands.md

EAP logs

  • log stream --predicate 'subsystem == "com.apple.eapol"'

Logs logged via logger

logger -is -t $title "Hello Logs"
log show --predicate 'eventMessage contains "Hello Logs"' --last 3m
View runAs.cmd
# Run Explorer as Seperate Process
runas /user:domain\username "explorer /separate"
# General runas
runas /user:administrator "C:\Path\To\program.EXE"
runas /profile /user:administrator "Drive:\folder\program"
View getFsUsage.sh
# Run fs_usage
sudo fs_usage -e -www | grep -i $searchTerm
View findHomeDirectory.sh
# Set USERNAME variable to user
USERNAME=""
USER_HOME=$(/usr/bin/dscl . read "/Users/${USERNAME}" | awk -F ':' '/NFSHomeDirectory/ {print $2}' | awk '{$1=$1};1')
View getCurrentUser.sh
# Python (deprecated):
CURRENT_USER=$(/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");')
# scutil:
CURRENT_USER=$(/bin/echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }')
CURRENT_USER_ID=$(printf %s 'show State:/Users/ConsoleUser' | scutil | awk '($1 == "UID") { print $NF; exit }')
CURRENT_USER_NAME=$(/usr/bin/dscl /Search -search /Users UniqueID "${CURRENT_USER_ID}" 2> /dev/null | awk '{ print $1; exit }')
View clearDNSCache.md

Flushing DNS

Ubuntu

  • sudo systemd-resolve --flush-caches

macOS

  • sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache

Windows

  • ipconfig /flushdns
View readManagedPreferences.py
# Uses managed Python to read preferences
managed_python3 -c 'from CoreFoundation import CFPreferencesCopyAppValue; print CFPreferencesCopyAppValue("key", "domain")'
View readWriteTests.sh
# Read test
dd if=tstfile bs=2048k of=/dev/null count=1024 2>&1 | grep sec | awk '{print "Read: " $1 / 1024 / 1024 / $5, "MB/sec" }'
# Write test
dd if=/dev/zero bs=2048k of=tstfile count=1024 2>&1 | grep sec | awk '{print "Write: " $1 / 1024 / 1024 / $5, "MB/sec" }'
View turnOffSpotlight.sh
# Toggle Spotlight
sudo mdutil -a -i off # Off
sudo mdutil -a -i on # On
# To remove the menu bar icon, run this Terminal command:
sudo chmod 600 /System/Library/CoreServices/Search.bundle/Contents/MacOS/Search && killall SystemUIServer