Skip to content

Instantly share code, notes, and snippets.

Last active Apr 25, 2022
What would you like to do?
macOS Cheatsheet - Commonly used commands for my macOS Setup
-- Automate your macOS a bit more, schedule Safari to open your favourite sites regularly at 7am to save a few seconds each morning.
# In terminal, type the following command which will allow you to edit current scheduled jobs with nano editor
# You might need to grant cron full disk access for this to work.
env EDITOR=nano crontab -e
# Then copy and paste the following lines. Control-X to exit nano. The new jobs will be schedulled.
# The samples below are to open Safari at 7am each morning with the specified URL. It should placed them in new tab if that's how your safari is setup. It's good to wake up each morning saving a few seconds loading the sites you read daily. You can also use similar schedule to download files, open apps, etc. To learn more about how to specify the time, check out
$ crontab -r where the -r flag removes current crontab configuration.
$ crontab -l where the -l to list crontab configuration is helpful if you can't remember the schedule format
0 7 * * * open -a Safari
0 7 * * * open -a Safari
0 7 * * * open -a Safari
0 7 * * * open -a Safari
0 7 * * * open -a 'Brave Browser'
-- If you want it to open in a new window, you can do it with Chrome/Brave with the following
open -na "Google Chrome" --args --new-window ""
open -na "Brave Browser" --args --new-window ""
-- macOS screenshot files location, stop cluttering your desktop folder
-- With current release of macOS, you don't need to do this, just open the screenshot app, select the folder to save to, that will become the default
# Make a new "Screenshots" folder inside your home folder to store all your new screenshots.
# Then run the following command in Terminal.
defaults write location ~/Screenshots; killall SystemUIServer
-- Fixing disk issues
# Find the disk number with the following command
diskutil list
# Then use the following command on HFS disk
sudo /sbin/fsck_hfs -drfy /dev/disk2s3
-- SSH Keys Ref:
chown root:root ~/.ssh/id_rsa*
chown user:user ~/.ssh/id_rsa*
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/
-- To merge many .ts videos
cd ts_files_directory
echo {1..500}.ts | tr " " "\n" > tslist
while read line; do cat $line >> combined.ts; done < tslist
-- To Install MongoDB with tools using homebrew
brew tap mongodb/brew
brew install mongodb-community
brew install mongodb-database-tools
-- To download thousands of URLs using CURL, make a long list of urls.txt
cat urls.txt | xargs -0 curl -O
-- Sometimes, I want to give a particulr app the full process priority
sudo renice -20 $(pgrep FaceTime)
-- To merge some AVI files without re-encoding, install mencoder, then
brew install mplayer
mencoder -oac copy -ovc copy 1.avi 2.avi 3.avi 4.avi 5.avi 6.avi -o final.avi
-- To loop through directories
for dir in *; do
echo $dir;
-- To loop through files in a directory
for file in *.avi; do
echo $file;
-- To open 2 copies of WeChat
nohup /Applications/ > /dev/null 2>&1 &
nohup /Applications/企业微信.app/Contents/MacOS/企业微信 > /dev/null 2>&1 &
-- Using osascript to send imessage, please change your full international phone number with country code and the + sign, no, not with the squid game phone number. also, if you really need it, "pip install osascript"
osascript -e 'tell application "Messages" to send "Hello World!" to buddy "+1192182919191"'
-- Counting how many sub-subfolders are over 1mb in size, change max/mindepth to have different folder levels
find . -maxdepth 2 -mindepth 2 -type d -exec du -hs {} \; | grep "M\t" | wc -l
-- Copy files with certain extensions (pdf, jpg in this example) to a new folder preserving folder structure
rsync -a --include '*/' --include '*.pdf' --include '*.jpg' --exclude '*' source_folder/ destination_folder/
-- To remove node and start again. Lesson: avoid installing node with homebrew
-- Also check
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
-- check after the above with "which node"
To convert all SVG to PNG of fixed 1200 height
brew install librsvg
find . -type f -name "*.svg" -exec bash -c 'rsvg-convert -h 1200 "$0" > "$0".png' {} \;
Too lazy to start another gist for now, just jotting down my frequently used regex patterns.
-- To strip HTML tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment