BSD vs GNU Commands
sed -irequires extension argument:sed -i '' 's/a/b/' file— empty string for no backup, Linux doesn't need itfinddoesn't support-printf— use-exec statorxargswithstat -finsteaddateuses different format flags:date -j -f '%Y-%m-%d' '2024-01-15' '+%s'—-jprevents setting timegrep -P(Perl regex) doesn't exist — usegrep -E(extended) or installggrepvia Homebrewxargsdefaults to/usr/bin/echonot the command — always specify the command explicitlyreadlink -fdoesn't exist — userealpathorpython3 -c "import os; print(os.path.realpath('path'))"
Homebrew Paths
Apple Silicon:
/opt/homebrew/bin,/opt/homebrew/libIntel:
/usr/local/bin,/usr/local/libCheck architecture:
uname -mreturnsarm64orx86_64Homebrew doesn't add to PATH automatically — check
~/.zprofilefor eval lineRunning x86 binaries:
arch -x86_64 /bin/bashthen install/run Intel-only tools
Keychain (Secrets)
Store:
security add-generic-password -a "$USER" -s "service_name" -w "secret_value" -URetrieve:
security find-generic-password -a "$USER" -s "service_name" -w-Uflag updates if exists — without it, duplicate entries errorKeychain prompts for access on first use — authorize permanently for automation
Delete:
security delete-generic-password -a "$USER" -s "service_name"
launchd (Services)
User agents:
~/Library/LaunchAgents/— runs as user when logged inSystem daemons:
/Library/LaunchDaemons/— runs at boot as rootLoad:
launchctl load -w ~/Library/LaunchAgents/com.example.plistUnload before editing:
launchctl unload— edits to loaded plists are ignoredCheck errors:
launchctl list | grep service_namethenlaunchctl error <exit_code>Logs:
log show --predicate 'subsystem == "com.example"' --last 1h
Privacy Permissions (TCC)
Automation scripts fail silently without Full Disk Access or Automation permissions
Grant in System Settings → Privacy & Security → corresponding category
Terminal and iTerm need separate permissions — granting to one doesn't grant to other
tccutil resetclears permissions:tccutil reset AppleEventsfor AutomationCheck granted permissions:
sqlite3 ~/Library/Application\ Support/com.apple.TCC/TCC.db "SELECT * FROM access"
defaults (Preferences)
Read:
defaults read com.apple.finder AppleShowAllFilesWrite:
defaults write com.apple.finder AppleShowAllFiles -bool trueDelete:
defaults delete com.apple.finder AppleShowAllFilesRestart app after changing:
killall FinderFind app bundle ID:
osascript -e 'id of app "App Name"'Export all:
defaults export com.apple.finder -outputs XML
File Operations
dittopreserves resource forks and metadata — use instead ofcpfor app bundlesCreate DMG:
hdiutil create -volname "Name" -srcfolder ./folder -format UDZO output.dmgMount DMG:
hdiutil attach image.dmg— returns mount point pathUnmount:
hdiutil detach /Volumes/NameExtended attributes:
xattr -l fileto list,xattr -c fileto clear allQuarantine removal:
xattr -d com.apple.quarantine app.app
Clipboard
Copy to clipboard:
echo "text" | pbcopyPaste from clipboard:
pbpasteCopy file contents:
pbcopy < file.txtPreserve RTF:
pbpaste -Prefer rtfClipboard works in SSH sessions to local machine — useful for remote file copying
Screenshots and Screen
Screenshot region to file:
screencapture -i output.pngScreenshot window:
screencapture -w output.pngScreenshot to clipboard:
screencapture -cHeadless (no UI):
screencapture -x— suppresses sound and cursorScreen recording requires Screen Recording permission in Privacy settings
Process Management
Prevent sleep:
caffeinate -i command— keeps system awake while command runsPrevent sleep with timeout:
caffeinate -t 3600— 1 hourCheck why not sleeping:
pmset -g assertionsPower settings:
pmset -gto view,sudo pmset -a sleep 0to disable sleepCurrent app in focus:
osascript -e 'tell application "System Events" to get name of first process whose frontmost is true'
Network
List interfaces:
networksetup -listallhardwareportsGet IP:
ipconfig getifaddr en0(Wi-Fi usually en0 on laptops)DNS servers:
scutil --dns | grep nameserverFlush DNS:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponderProxy settings:
networksetup -getwebproxy "Wi-Fi"
System Integrity Protection
Check status:
csrutil statusDisable (Recovery Mode only):
csrutil disable— not recommended for productionProtected paths:
/System,/usr(except/usr/local),/sbin,/binCan't modify these even as root — design your automations around this
Logs
Stream live:
log stream --predicate 'process == "processname"'Search recent:
log show --last 1h --predicate 'eventMessage contains "error"'Subsystem filter:
log show --predicate 'subsystem == "com.apple.example"'Save to file:
log collect --output ./logs.logarchive— opens in Console.app
Automation Tips
Open URL:
open "https://example.com"— uses default browserOpen app:
open -a "Safari"— by name, not pathOpen file with specific app:
open -a "TextEdit" file.txtRun AppleScript:
osascript -e 'tell application "Finder" to get name of home'Spotlight search:
mdfind "kMDItemDisplayName == 'filename.txt'"— faster than find for indexed files