Skip to content

Instantly share code, notes, and snippets.

@eplt
Last active December 2, 2025 11:49
Show Gist options
  • Select an option

  • Save eplt/027c99215e37a3a138c32b19a944b05d to your computer and use it in GitHub Desktop.

Select an option

Save eplt/027c99215e37a3a138c32b19a944b05d to your computer and use it in GitHub Desktop.
macOS Cheatsheet - Commonly used commands for my macOS Setup
-- Automation & Scheduling --
Classic Cron:
In terminal, type:
env EDITOR=nano crontab -e
To remove all scheduled jobs: crontab -r
To list all scheduled jobs: crontab -l
Sample to open Safari every morning:
0 7 * * * open -a Safari http://www.bbc.com/news
0 7 * * * open -a Safari http://money.cnn.com
0 7 * * * open -a Safari https://flipboard.com/section/technology-c5o31di9kg9ea7p6
0 7 * * * open -a Safari https://www.macrumors.com
0 7 * * * open -a 'Brave Browser' http://www.bbc.com
To open Chrome/Brave in new window:
open -na "Google Chrome" --args --new-window "https://www.bbc.com"
open -na "Brave Browser" --args --new-window "https://www.bbc.com"
Modern Scheduling with launchd:
Paste into ~/Library/LaunchAgents/com.user.safari-opener.plist
(see online for plist tutorial)
After saving plist:
launchctl load ~/Library/LaunchAgents/com.user.safari-opener.plist
launchctl list | grep safari-opener
launchctl unload ~/Library/LaunchAgents/com.user.safari-opener.plist
File/Folder Change Monitoring (Automation):
brew install fswatch
fswatch -o ~/Downloads | xargs -n1 -I {} echo "File changed"
-- System Management --
Change screenshot folder:
defaults write com.apple.screencapture location ~/Screenshots; killall SystemUIServer
Disk checklist:
diskutil list
sudo /sbin/fsck_hfs -drfy /dev/disk2s3
Interactive disk space analysis:
brew install ncdu
ncdu ~
sudo ncdu /
-- Performance & Monitoring --
Give process full priority:
sudo renice -20 $(pgrep FaceTime)
Process monitoring:
brew install htop
htop
vm_stat
ps aux --sort=-%mem | head -20
powermetrics -n 1 --samplers cpu_power,gpu_power
-- File & Batch Operations --
Loop through:
for dir in *; do echo $dir; done
for file in *.avi; do echo $file; done
Delete all .flac:
find . -name '*.flac' -delete
Delete PDFs below 1KB:
find . -type f -name "*.pdf" -size -1k -delete
Merge TS videos:
cd ts_files_directory
echo {1..500}.ts | tr " " "\n" > tslist
while read line; do cat $line >> combined.ts; done < tslist
AVI merge:
brew install mplayer
mencoder -oac copy -ovc copy 1.avi 2.avi 3.avi 4.avi 5.avi 6.avi -o final.avi
Merge + Sort MP4s:
rm list.txt; for f in *.mp4 ; do echo file '$f' >> list.txt; done && sort -V list.txt > list-sort.txt && ffmpeg -f concat -safe 0 -i list-sort.txt -c copy stitched-video.mp4 ; rm list.txt list-sort.txt
Batch compress multiple files (performance):
brew install parallel
ls *.mp4 | parallel --jobs 4 'ffmpeg -i {} -c:v libx264 -preset fast -crf 28 {.}_compressed.mp4'
-- Development & DevOps --
SSH key permissions:
chown root:root ~/.ssh/id_rsa*
chown user:user ~/.ssh/id_rsa*
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
Persistent SSH tunnel:
ssh -NTf -L localhost:6379:remoteserver.com:6379 [email protected]
See ~/.ssh/config for more advanced setups.
Homebrew & Docker troubleshooting on Apple Silicon:
curl -O https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh
/bin/bash uninstall.sh --path=/usr/local
brew install docker
# Pull correct architecture images:
docker pull --platform linux/arm64 python:3.11
# Use buildx for multi-arch:
docker buildx build --platform linux/amd64,linux/arm64 -t myapp:latest .
Install MongoDB:
brew tap mongodb/brew
brew install mongodb-community
brew install mongodb-database-tools
-- Security, Network & Code Signing --
Remove App Quarantine:
xattr -d com.apple.quarantine /Applications/Lepton.app
xattr -r -d com.apple.quarantine "/Applications/full app path"
Code signing / notarization:
codesign -f -s - --timestamp=none --all-architectures "/Applications/full app path"
codesign -v /Applications/YourApp.app
spctl -a -v /Applications/YourApp.app
Network diagnostics:
brew install dig mitmproxy nethogs
mitmproxy -p 8080
curl -x 127.0.0.1:8080 https://api.example.com/endpoint
openssl s_client -connect api.example.com:443 -showcerts
netstat -in
sudo nethogs
-- Reference & Quick Tools --
iCloud Drive folder:
$HOME/Library/Mobile\ Documents/com~apple~CloudDocs
$HOME/Library/Mobile\ Documents
Backup dotfiles:
mkdir -p ~/dotfiles
cp ~/.ssh/config ~/.gitconfig ~/.zshrc ~/dotfiles/
ln -sf ~/dotfiles/.zshrc ~/.zshrc
cd ~/dotfiles
git init
git add .
git commit -m "Initial config backup"
git remote add origin [email protected]:yourusername/dotfiles.git
git push -u origin main
Split big folder into chunks of 1000 files:
i=0; for f in *; do d=dir_$(printf %03d $((i/1000+1))); mkdir -p $d; mv "$f" $d; let i++; done
Remove NodeJS completely:
sudo rm /usr/local/bin/npm
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
sudo rm -rf ~/.node-gyp
sudo rm /opt/local/bin/node
sudo rm /opt/local/include/node
sudo rm –rf /usr/local/bin/node
sudo rm -rf /opt/local/lib/node_modules
sudo rm -rf /usr/local/bin/npm
sudo rm -rf /usr/local/share/man/man1/node.1
sudo rm -rf /usr/local/lib/dtrace/node.d
sudo rm -rf /usr/local/lib/node_modules
System extension cleanup:
sudo rm -rf /Library/Extensions/<kextname.kext>
sudo kextcache -i /
sudo kextcache --clear-staging
sudo reboot
-- Apple Silicon Specific --
CMake fix for x86_64 library:
set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE INTERNAL "" FORCE)
Install Rosetta:
softwareupdate --install-rosetta
-- Scripting & Automation --
AppleScript (Brave tabs to Safari):
tell application "Brave Browser"
set tab_list to every tab in the front window
repeat with the_tab in tab_list
set the_url to the URL of the_tab
tell application "Safari" to open location the_url
end repeat
end tell
Send iMessage with osascript:
osascript -e 'tell application "Messages" to send "Hello World!" to buddy "+1192182919191"'
Open 2 copies of WeChat:
nohup /Applications/WeChat.app/Contents/MacOS/WeChat > /dev/null 2>&1 &
nohup /Applications/企业微信.app/Contents/MacOS/企业微信 > /dev/null 2>&1 &
Generate random passwords:
for i in $(seq 1 5); do LANG=C && echo $(tr -dc 'A-Za-z0-9!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~' < /dev/urandom | head -c 20); done
Hide user account from login screen:
sudo dscl . create /Users/<hiddenuser> IsHidden 1
-- Data Processing & Regex --
Strip HTML tags (regex):
\<[^\>]*\>
Other useful patterns:
(https?|ftp|ssh)://[^\s/$.?#].[^\s]* # URL
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} # Email
\d+\.?\d* # Number
[a-fA-F0-9]{32}|[a-fA-F0-9]{64} # MD5/SHA256
\b[13][a-km-zA-HJ-NP-Z1-9]{25,34}\b # Bitcoin Address
"([^"\\]|\\.)*" # JSON String
0x[a-fA-F0-9]{40} # Ethereum
Python one-liners:
Parse JSON:
curl -s https://api.example.com/data | python3 -m json.tool | grep "price"
Extract from CSV:
python3 -c "import csv;data=[float(row['price']) for row in csv.DictReader(open('prices.csv'))];print(f'Mean: {sum(data)/len(data)}, Max: {max(data)}')"
Extract URLs from text:
cat document.txt | python3 -c "import sys, re; print('\\n'.join(re.findall(r'https?://\\S+', sys.stdin.read())))"
Batch rename .txt to .md:
python3 -c "import os, re; [os.rename(f, re.sub(r'\\.txt$', '.md', f)) for f in os.listdir('.') if f.endswith('.txt')]"
Count lines of code:
find . -name "*.py" -type f -exec wc -l {} + | tail -1
Batch extract EPUB text:
for epub in *.epub; do
echo "Processing $epub..."
unzip -q -c "$epub" | strings | grep -v "^$" > "${epub%.epub}.txt" 2>/dev/null && \
echo "✓ $epub processed" || echo "✗ Failed: $epub"
done
-- Miscellaneous --
Install common CLI tools:
brew install mplayer htop ncdu parallel mitmproxy docker mongodb/brew fdupes fswatch dig nethogs
Find and remove duplicates:
fdupes -r .
fdupes -rdN .
Download many URLs with curl:
cat urls.txt | xargs -0 curl -O
Preserve folder structure when copying files:
rsync -a --include '*/' --include '*.pdf' --include '*.jpg' --exclude '*' source_folder/ destination_folder/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment