π¦ ClawHub
macOS
by @ivangdavila
macOS system administration, command-line differences from Linux, and automation best practices.
TERMINAL
clawhub install macosπ About This Skill
name: macOS description: macOS system administration, command-line differences from Linux, and automation best practices. metadata: category: system skills: ["macos", "osx", "apple", "darwin", "terminal"]
BSD vs GNU Commands
sed -i requires extension argument: sed -i '' 's/a/b/' file β empty string for no backup, Linux doesn't need itfind doesn't support -printf β use -exec stat or xargs with stat -f insteaddate uses different format flags: date -j -f '%Y-%m-%d' '2024-01-15' '+%s' β -j prevents setting timegrep -P (Perl regex) doesn't exist β use grep -E (extended) or install ggrep via Homebrewxargs defaults to /usr/bin/echo not the command β always specify the command explicitlyreadlink -f doesn't exist β use realpath or python3 -c "import os; print(os.path.realpath('path'))"Homebrew Paths
/opt/homebrew/bin, /opt/homebrew/lib/usr/local/bin, /usr/local/libuname -m returns arm64 or x86_64~/.zprofile for eval linearch -x86_64 /bin/bash then install/run Intel-only toolsKeychain (Secrets)
security add-generic-password -a "$USER" -s "service_name" -w "secret_value" -Usecurity find-generic-password -a "$USER" -s "service_name" -w-U flag updates if exists β without it, duplicate entries errorsecurity delete-generic-password -a "$USER" -s "service_name"launchd (Services)
~/Library/LaunchAgents/ β runs as user when logged in/Library/LaunchDaemons/ β runs at boot as rootlaunchctl load -w ~/Library/LaunchAgents/com.example.plistlaunchctl unload β edits to loaded plists are ignoredlaunchctl list | grep service_name then launchctl error log show --predicate 'subsystem == "com.example"' --last 1hPrivacy Permissions (TCC)
tccutil reset clears permissions: tccutil reset AppleEvents for Automationsqlite3 ~/Library/Application\ Support/com.apple.TCC/TCC.db "SELECT * FROM access"defaults (Preferences)
defaults read com.apple.finder AppleShowAllFilesdefaults write com.apple.finder AppleShowAllFiles -bool truedefaults delete com.apple.finder AppleShowAllFileskillall Finderosascript -e 'id of app "App Name"'defaults export com.apple.finder - outputs XMLFile Operations
ditto preserves resource forks and metadata β use instead of cp for app bundleshdiutil create -volname "Name" -srcfolder ./folder -format UDZO output.dmghdiutil attach image.dmg β returns mount point pathhdiutil detach /Volumes/Namexattr -l file to list, xattr -c file to clear allxattr -d com.apple.quarantine app.appClipboard
echo "text" | pbcopypbpastepbcopy < file.txtpbpaste -Prefer rtfScreenshots and Screen
screencapture -i output.pngscreencapture -w output.pngscreencapture -cscreencapture -x β suppresses sound and cursorProcess Management
caffeinate -i command β keeps system awake while command runscaffeinate -t 3600 β 1 hourpmset -g assertionspmset -g to view, sudo pmset -a sleep 0 to disable sleeposascript -e 'tell application "System Events" to get name of first process whose frontmost is true'Network
networksetup -listallhardwareportsipconfig getifaddr en0 (Wi-Fi usually en0 on laptops)scutil --dns | grep nameserversudo dscacheutil -flushcache; sudo killall -HUP mDNSRespondernetworksetup -getwebproxy "Wi-Fi"System Integrity Protection
csrutil statuscsrutil disable β not recommended for production/System, /usr (except /usr/local), /sbin, /binLogs
log stream --predicate 'process == "processname"'log show --last 1h --predicate 'eventMessage contains "error"'log show --predicate 'subsystem == "com.apple.example"'log collect --output ./logs.logarchive β opens in Console.appAutomation Tips
open "https://example.com" β uses default browseropen -a "Safari" β by name, not pathopen -a "TextEdit" file.txtosascript -e 'tell application "Finder" to get name of home'mdfind "kMDItemDisplayName == 'filename.txt'" β faster than find for indexed files