Skip to content

Instantly share code, notes, and snippets.

Embed
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. https://osxdaily.com/2020/04/27/fix-cron-permissions-macos-full-disk-access/
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 http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/
$ crontab -r where the -r flag removes current crontab configuration.
$ crontab -l where the -l to list crontab configuration
https://crontab.guru/ is helpful if you can't remember the schedule format
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
-- 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 "https://www.bbc.com"
open -na "Brave Browser" --args --new-window "https://www.bbc.com"
-- macOS screenshot files location, stop cluttering your desktop folder
# Make a new "Screenshots" folder inside your home folder to store all your new screenshots.
# Then run the following command in Terminal.
defaults write com.apple.screencapture 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: https://gist.github.com/grenade/6318301
chown root:root ~/.ssh/id_rsa*
chown user:user ~/.ssh/id_rsa*
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
-- 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;
done
-- To loop through files in a directory
for file in *.avi; do
echo $file;
done
-- To 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 &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment