Mac OS

Useful Shortcuts

If you find these hard to remember, there’s a useful application called CheatSheet that you can use:

  brew cask install cheatsheet

After it’s installed, you can hold ⌘ and the list of keyboard shortcuts for the current application will appear.

Shortcut Function  
⌘ ⇧ [ Switch to previous tab  
⌘ ⇧ ] Switch to next tab  
⌘ [ Go back to previous page  
⌘ ] Go forward to next page  
⌘ ` Cycle through open windows of current app  
⌘ [tab] Cycle through open apps  
⌃ ↓ View all open windows of current app
⌃ ↑ View all open windows of every app  

Sleep, Restart, Shut Down, Log Out

Shorcut Function
⌥ ⌘ ⏏︎ Sleep
⌃ ⌘ ⏏︎ Restart
⌃ ⌥ ⌘ ⏏︎ Shut down
⌥ ⇧ ⌘ Q Log out

Document Editing

These work when editing text using Safari, Notes, and Mail, and any Mac OS application in general. They aren’t arbitrary, they’re the emacs hotkeys, and work on many applications, not just ones on Mac OS.

Shortcut Function
⌃ A Move to the beginning of the line
⌃ E Move to the end of the line
⌃ H Delete the character left of the the cursor
⌃ D Delete the character right of the cursor
⌃ U Delete all text left of the cursor
⌃ K Delete all text right of the cursor
⌃ O Add a newline without moving the cursor
⌃ T Swap the characters left and right of the cursor

Cursor Movement

If you’re ever stuck without arrow keys (it could happen!) you can take advantage of these 4 shortcuts.

Shortcut Function
⌃ F Move cursor →
⌃ B Move cursor ←
⌃ P Move cursor ↑
⌃ N Move cursor ↓

Tip: These look arbitrary, but they use a helpful pneumonic, hidden as it may be. Forward, Backward, Previous, Next.


Shortcut Function
⌘ , Open preferences window
⌘ ⇧ / Open help menu for current app
⌘ ⌃ F Open app in full-screen
⌥ ⌘ I Open inspect element

Tip: You can open inspect element in many more apps than you think. Give it a try!

  • Disable sleep entirely

    sudo systemsetup -setcomputersleep Never
  • Immediately put the computer to sleep

    pmset sleepnow
  • Schedule for the computer to regularly wake up (or boot) on weekdays @ 7:45AM

    pmset repeat wakeorpoweron MTWRF 07:45:00
  • Schedule for the computer to sleep on 12/24 @ 8:00AM

    pmset schedule sleep "12/24/2019 08:00:00"
  • Schedule for the computer to wake on 12/24 @ 8:00PM

    pmset schedule wake "12/24/2019 20:00:00"
  • Restart the computer immediately

    sudo reboot now
  • Shut down the computer immediately

    sudo shutdown now
  • Dangerously shut the computer down immediately

    sudo halt


Shortcut Function
⌘ ⌫ Send file to trash
⌥ ⌘ ⌫ Completely delete a file
⌥ ⌘ ⇧ ⌫ Empty the trash
⌘ ⇧ N Create a new folder
⌥ ⌘ V Transfer copied file/folder to the current folder
⌘ ⇧ . Show hidden files/folders
⌘ E Eject selected disk/drive
Shortcut Function
⌘ ↑ Open the parent folder
⌘ ↓ Open the file/folder
⌘ → Open the folder (list view)
⌘ ← Close the folder (list view)

Opening Folders

Shortcut Function
⌘ ⇧ G Go to folder
⌘ ⇧ D Open the Desktop folder
⌘ ⇧ O Open the Documents folder
⌥ ⌘ L Open the Downloads folder
⌘ ⇧ H Open the Home folder
⌘ ⇧ A Open the Applications folder
⌘ ⇧ R Open the AirDrop folder
⌘ ⇧ I Open the iCloud folder

Adjusting the Finder Window

Shortcut Function
⌘ ⌥ P Show/hide the path bar
⌘ ⌥ S Show/hide the side bar
⌘ ⌥ T Show/hide the toolbar
⌘ ⇧ T Show/hide the tab bar
⌘ / Show/hide the status bar
⌘ ⇧ P Show/hide preview of selected file
⌘ 1 View folder’s items as icons
⌘ 2 View folder’s items as list
⌘ 3 View folder’s items as columns
⌥ ⌘ ⌃ 1 Sort files by name
⌥ ⌘ ⌃ 2 Sort files by type
⌥ ⌘ ⌃ 4 Sort by date added
⌥ ⌘ ⌃ 5 Sort by date modified


Shortcut Function
⌘ ⇧ \ Show all tabs
⌘ L Select the current page’s URL
⌘ ⇧ R Open in reader-view
⌘ ⇧ I Mail link of current page
⌥ [click] Download linked file
⌘ [click] Open link in a new tab
⌘ D Add current page to bookmarks
⌘ ⇧ D Add current page to reading list
⌥ ⌘ L Open the downloads folder
⌥ ⌘ E Reset the cache
⌘ ⇧ C Start/stop select element
⌥ ⌘ C Open JavaScript Console
⌥ ⌘ I Open/close inspect element (also closes JavaScript console)
⌥ ⌘ R Hard refresh page


Shortcut Function
⌘ ⇧ N Get new messages
⌘ N Write new message
⌥ ⌘ F Search mail for message
⌘ ⇧ D Send message
⌥ ⌘ J Empty junk mailbox
⌘ ⇧ ⌫ Empty trash mailbox
⌘ 1 View inbox
⌘ 2 View drafts
⌘ 3 View sent
⌘ 4 View junk
⌘ 5 View trash


Shortcut Function
⌥ ⌘ D Show/Hide the dock

Tip: You can add the control character to your usual screenshot command, to have screenshots save directly to your clipboard.

Change screenshot capture type

By default, screenshots save to .png but you can change this setting to .jpg or .pdf

Set default screen capture as .jpg

defaults write type jpg && killall SystemUIServer

Change screenshot capture location

By default, screenshots save to ~/Desktop. I prefer them to be saved to ~/Downloads. You can change the screenshot capture location by running this command.

defaults write location /Users/austin/Downloads && killall SystemUIServer

Warning: I had a little bit of trouble with this command. I don’t think it works anymore. As of Mac OS Mojave, you have to press ⌘ ⇧ 5, click options and then select Other Location… to choose a new default save location for screenshots.

Screenshot directly from terminal

There’s a hidden terminal command screencapture that you can use to capture a screenshot of your current window.

Capture the screen, save to example.png

  screencapture example.png
  • Capture the screen, save to the clipboard

    screencapture -c
  • Capture the screen, disable the “click” sound effect

    screencapture -x example.png
  • Capture the screen, (but after 10 second delay)

    screencapture -T 10 example.png &

Start screen recording from the terminal

You can even use screencapture to record video. The -V flag specifies to capture a video and the -A flag specifies to capture audio as well.

  • Record the screen for 10 seconds

    screencapture -V 10 example.mp4 &

This is mostly just for fun, it’s not as practical as the other ways to go about doing the same thing. If you don’t want to use the terminal type ⌘ ⇧ 5 which will give you a host of options to choose from. This is a new feature in OS X Mojave.

Change default screenshot location

I like to put my screenshots in the ~/Downloads directory. Luckily there’s a terminal command for that.

  • Set the directory of all future screenshots.

    defaults write location ~/Downloads && killall SystemUIServer


Custom Sound Effects

You can change the alert sound on your Mac to any .aiff file. Your alert sounds are located in ~/Library/Sounds.

  • Convert a .mp3 to .aiff

    ffmpeg -i Input.mp3 Output.aiff
    cp Output.aiff ~/Library/Sounds/Custom.aiff

Move cursor with the mouse in terminal

This is a cool trick I just discovered. Start typing out a command on the terminal, and then hold ⌥

Now try clicking on a different part of the command you’re entering. It will move the cursor to that location!

Update Software in the Terminal

You can actually update the software on your computer directly from the terminal.

  • List available software updates

    softwareupdate -l
  • The -l flag is the list option

  • Install all updates

    # Short form
    sudo softwareupdate -iaR
    # Long form
    sudo softwareupdate --install --all --restart
  • The -i flag is the install option
  • The -a flag is the all option
  • The -r flag is the restart option, so the computer will restart and install the updates after they are downloaded


  • The default terminal font, SF Mono, is by default hidden from the Font Book, and is available exclusively for use in the terminal app. To copy SF Mono to your computer’s Font Book, run this command.

    cp -R /System/Applications/Utilities/* /Library/Fonts

Disable User Photo

  • Although the GUI doesn’t give us an option to disable user-pictures, you can do it with the terminal command below.

    sudo dscl . delete /Users/tommy jpegphoto

Setting Keyboard Shortcuts from Terminal

Store your keyboard shortcuts in the directory ~/Library/KeyBindings/DefaultKeyBinding.dict. Note that you have to first create ~/Library/KeyBindings since it won’t exist at first.

  • @ : ⌘
  • ^ : ⌃
  • ~ : ⌥
  • $ : ⇧

  • : \U2190
  • : \U2191
  • : \U2192
  • : \U2193

Note: Any shortcuts you make using this method will not appear in the keyboard shortcut settings page in your computer.

Fix Permissions

If you mess up your /etc files, like I did when I accidentally made every file executable, you can run this command to reset all of the permissions.

  • Reset system file permissions to default

    diskutil resetUserPermissions / $(id -u)

If you mess up your /etc/sudoers file, you’ll have to boot into single-user mode with ⌘ S during power on. From there, you can enter the following commands.

  • Reset sudoers file

    mount -uw /
    chown root:wheel /etc/sudoers
    chmod 440 /etc/sudoers


defaults is a powerful tool to utilize when exporting and importing settings across machines. Although there is no built-in method to sync keyboard shortcuts across computers, you can use the defaults program to set various keyboard shortcuts. When doing so, refer to the syntax below for how to denote modifier keys:

Tip: You can replace NSGlobalDomain with the -g flag to specify that the defaults command is global in scope.

  • Disabling key repeat

    defaults write -g InitialKeyRepeat -int 10
  • Resetting key repeat to default settings

    defaults write -g InitialKeyRepeat -int 15 # 225 ms
    defaults write -g KeyRepeat -int 2 # 30 ms

Customize Launch Application for File Extension

The file that controls which app launches for a file is located here:


Delete FaceTime Popup

pkill -9 FaceTimeNotif

macOS notes

  • Notes are stored in a sqlite database, located on your computer at ~/Library/Containers/

Default Application

You can install the command duti on homebrew to configure the default application that opens when you click on a file with a particular file extension. I’ve included an example below:

  • Setting default application used for .c files.

    # Set apple as the default editor for .c files
    duti -s public.c editor
    # Check the current handlers performed by a UTI
    duti -l
    # Describe information about the default app for extension `mp4`
    duti -x mp4

Delete FaceTime Popup

pkill -9 FaceTimeNotif

macOS notes

  • Notes are stored in a SQLite database, located on your computer at ~/Library/Containers/


# Convert `example.svg` into a 1000x1000 .png file
qlmanage -ts 1000 -o . example.svg


The networksetup command allows you to configure your System Preference’s Network settings directly from your terminal.

  • Get the current DNS servers

    networksetup -getdnsservers Wi-Fi
  • Configure the DNS servers

    networksetup -setdnsservers Wi-Fi 2606:4700:4700::1111 2606:4700:4700::1001
  • Get the local machine’s MAC address

    networksetup -getmacaddress Wi-Fi | awk '{print $3}'
  • Configure the SOCKS proxy

    ssh -fNCD 3339
    networksetup -setsocksfirewallproxy Wi-Fi 3339
  • Enable the SOCKS proxy

    networksetup -setsocksfirewallproxystate Wi-Fi on
  • Disable the SOCKS proxy

    networksetup -setsocksfirewallproxystate Wi-Fi off


There is a hidden command, called airport. To use it, add the following directory to your ${PATH}

  • Scan available WiFi networks

    airport -s
  • Disconnect from the current WiFi network

    airport -z
  • List preferred wireless networks

    networksetup -listpreferredwirelessnetworks en0
  • Remove a preferred wireless network

    networksetup -removepreferredwirelessnetwork en0 <network>
  • Connect to a WiFi Network

    networksetup -setairportnetwork en0 <WiFi name> <password>


  • Get the computer’s name

    scutil --get ComputerName
  • Set the computer’s name

    scutil --set ComputerName "Tommy's MacBook Pro"
  • Get the host name

    scutil --get HostName
  • Set the host name

    scutil --set HostName "nova"
  • Get the localhost name (used for Bonjour)

    scutil --get LocalHostName
  • Set the localhost name (used for Bonjour)

    scutil --set LocalHostName "nova"


  • If you have a Time Capsule, you can use the tmutil utility to interface with Time Machine from your terminal.

  • Backups are stored in the following location:

    tmutil latestbackup
    # => /Volumes/Time Machine Backups/Backups.backupdb/My Macbook Pro/2019-08-07-061700

Note: You have to run all of these as root, so before using tmutil, start with sudo -i

  • Turn on Time Machine

    tmutil enable
  • Turn off Time Machine

    tmutil disable
  • Start backing up to the Time Capsule

    tmutil startbackup
  • Stop backing up to the Time Capsule

    tmutil stopbackup

Saving Local Snapshots

By default, Time Machine will create local snapshots, locally stored backup volumes when it can’t connect to your Time Capsule.

  • Enable Local Snapshots

    tmutil disablelocal
  • Disable Local Snapshots

    tmutil enablelocal

Excluding Certain Files & Folders

By default, Time Machine will back up everything on your drive. You may, however, have data from large directories stored elsewhere. If so, it might be a good idea to exclude that directory from Time Machine’s backups, in the interest of saving space.

  • Exclude files in the directory ~/Downloads from backups

    tmutil addexclusion ~/Downloads
  • Re-enable backups for files in the directory ~/Downloads

    tmutil removeexclusion ~/Downloads

Note: By default, Time Machine will continue to ignore the files in an excluded directory even if you move the directory somewhere else. To have an absolute path excluded instead, use the -p flag.

  • Exclude files in the absolute path ~/Downloads from backups

    tmutil addexclusion -p ~/Downloads
  • Re-enable backups for files in the absolute path ~/Downloads

    tmutil removeexclusion -p ~/Downloads

You can also check if a given file, directory, or volume is excluded

  • Check if a file is excluded

    tmutil isexcluded ~/Downloads
    # => [Included] /Users/austin/Downloads

Restoring Files

  tmutil restore


macOS has a more robust alternative to cron which allows daemon processes to be triggered on a systematic fashion. Using the launchctl (launch control) command, you can create daemon processes that will automatically run by the system.

These files take the form of plist files and are found in several system directories:

  • /Library/LaunchAgents
  • /Library/LaunchDaemons
  • /System/Library/LaunchAgents
  • /System/Library/LaunchDaemons
  • ${HOME}/Library/LaunchAgents

If you write or install personal plist files, they will ideally go in the home directory. A good example file to begin understanding the syntax can be located in /System/Library/LaunchDaemons/ssh.plist, which is the file used to launch the ssh daemon server that listens for incoming ssh connections.

Sample launch agent, located in ~/Library/LaunchAgents/com.example.transmission.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">
      <!-- The absolute path to the executable file -->

      <!-- The first argument supplied to the program -->

      <!-- The second argument supplied to the program -->


If you’re setting up processes in /Library/LaunchDaemons, which are run as the root user, then make sure to set the file permissions appropriately using chown root:wheel <file> and chmod 644 <file>

  • View launchctl information about a daemon process by its PID:

    sudo launchctl profinfo <PID>
  • View information about all services pertaining to a user’s UID:

    launchctl print user/$UID
  • View information about a particular running service under a user’s UID:

    # ~/Library/LaunchAgents/
    launchctl print
  • For all daemon processes owned by the current user, print true if they are disabled

    launchctl print-disabled user/$UID

    Note: launchtl keeps an un-erasable record of disabled/enabled launch daemons. If you make a typo when adding daemon, and disable it, there is no way to erase it as an entry.

  • Enable a daemon service

    launchctl enable user/$UID/
  • Disable a daemon service

    launchctl disable user/$UID/
  • Launch a daemon service

    launchctl kickstart
  • Launch any executable file with arguments as a launchctl

    launchctl submit -l -- /path/to/executable 'arg1' 'arg2' 'arg3'

Create User from Command Line

Adding a new user to a Mac computer from a Terminal window requires you to define the user’s name, set a password, create the user’s home directory and configure their system permissions.

  1. Create a user named tommy
  dscl . -create /Users/tommy
  1. Set tommy’s shell to /bin/zsh
  dscl . create '/Users/tommy' UserShell '/bin/zsh'
  1. Set Tommy’s have the home directory /Users/tommy
  dscl . create '/Users/tommy' NFSHomeDirectory '/Users/tommy'
  createhomedir -u tommy -c
  1. Set tommy’s RealName to Tommy Trojan
  dscl . create '/Users/tommy' RealName 'Tommy Trojan'
  1. Give tommy a UID number, (for instance, 502)
  dscl . -create '/Users/tommy' UniqueID 502
  1. Give tommy the primary group ID of 20 (the default for the staff group on macOS)
  dscl . -create '/Users/username' PrimaryGroupID 20
  1. Give tommy the password fighton
  dscl . -passwd /Users/tommy 'fighton'
  1. Add tommy to the list of user’s that can be logged into with ssh
  dseditgroup -o edit -t user -a tommy
  1. Optionally add tommy to the list of admin users on the computer
  dseditgroup -o edit -d tommy -t user admin

Hidden Users

  • Allow the creation of secret users, hidden if their UID is 500 or lower

    sudo defaults write /Library/Preferences/ Hide500Users -bool YES
  • Make the user tommy a hidden user

    # Enabling hidden status
    sudo dscl . create '/Users/tommy' IsHidden 1
    # Disabling hidden status
    sudo dscl . create '/Users/tommy' IsHidden 0
  • Disable the Other... user from appearing in the login screen

    sudo defaults write /Library/Preferences/ SHOWOTHERUSERS_MANAGED -bool false
  • Add tommy to the list of hidden users

    sudo defaults write /Library/Preferences/ HiddenUsersList -array-add "tommy"
  • Hide the public share folder for the user whose long name is Tommy Trojan

    sudo dscl . delete "/SharePoints/Hidden Tommy Trojan's Public Folder"
  • Force the user tommy to set a new password

    sudo dscl . passwd '/Users/tommy' ''
    sudo pwpolicy -u username -setpolicy 'newPasswordRequired=1'
    sudo rm -r ~tommy/Library/Keychains/*
  • Get a list of all users short names

    sudo dscl . -list /Users
  • Get detailed info on a particular user

    sudo dscl . -read /Users/<username>
  • Get a specific value from a user

    dscl . -read /Users/<username> <key>
  • Get detailed info on all users

    dscl . -readall /Users
  • Get a specific value from all users

    dscl . -readall /Users <key>
  • Get concise information about all users

    dscl . ls /Users
  • Get all of the groups that user root is associated with

    dscl . -search /Groups GroupMembership root
  • Get the name os all of the groups

    dscl . ls /Groups
  • Check if the user tommy is a member of the group admin

    dseditgroup -o checkmember -m tommy admin
  • Add tommy to the list of users who are members of the admin group

    dseditgroup -o edit -a tommy -t user admin

    Tip: This is the command that is equivalent to checking the box “Allow user to administer this computer” on the Users & Groups page

  • Remove tommy from the list of users who are members of the admin group

    dseditgroup -o edit -d tommy -t user admin

Single User Mode

  • Reboot the computer into single user mode

    sudo launchctl reboot -s system

Power Sound

Playing the power sound

  afplay /System/Library/CoreServices/

System Integrity Protection

If you need to make changes to the file system, it might require disabling system integrity protection. By default, the following directories are protected:

  1. /System
  2. /usr
  3. /bin
  4. /sbin
  5. /var

There are three directories that are not protected:

  1. /Applications
  2. /Library
  3. /usr/local
  • Disabling system integrity protection

    csrutil disable
  • Enabling system integrity protection

    csrutil enable
  • Checking system integrity protection

    csrutil status

Configuring the Login Page

  • Show additional info by clicking the clock in the top-right corner

    sudo defaults write /Library/Preferences/ AdminHostInfo IPAddress
  • Adding a welcome message to the login page

    # [ Adding the message ]
    sudo defaults write /Library/Preferences/ LoginwindowText -string 'Welcome back'
    # [ Removing the message ]
    sudo defaults delete /Library/Preferences/ LoginwindowText
  • Adding a script to run at login

    sudo defaults write LoginHook /path/to/script

    Note: It’s preferrable to have these processes launch as LaunchAgents, but LoginHooks still work in the latest version of macOS.

  • Adding a graphic+text banner to appear upon login

    sudo cp ./banner /Library/Security/PolicyBanner
  • Disable buttons on the login page

    sudo defaults write /Library/Preferences/ ShutDownDisabled -bool true
    sudo defaults write /Library/Preferences/ RestartDisabled -bool true
    sudo defaults write /Library/Preferences/ SleepDisabled -bool true
  • Reenable buttons on the login page

    sudo defaults write /Library/Preferences/ ShutDownDisabled -bool false
    sudo defaults write /Library/Preferences/ RestartDisabled -bool false
    sudo defaults write /Library/Preferences/ SleepDisabled -bool false
  • Disable the user icons from the login page (this sets the “username & password” format as the default for the login page)

    sudo defaults write /Library/Preferences/ SHOWFULLNAME -bool true

    Tip: You can also just press option-return to toggle this view-mode if you’d rather not enable it by default


Something learned from man hdiutil: /dev/rdisk nodes are character-special devices, but are “raw” in the BSD sense and force block-aligned I/O. They are closer to the physical disk than the buffer cache. /dev/disk nodes, on the other hand, are buffered block-special devices and are used primarily by the kernel’s filesystem code. In layman’s terms /dev/rdisk goes almost directly to disk and /dev/disk goes via a longer more expensive route

  • View available storage devices

    diskutil list
  • Erase a hard drive’s partitions

    sudo diskutil partitionDisk /dev/disk2 1 MBR "Free Space" "%noformat%" 100%
  • Copy image to a new hard drive

    diskutil unmount /dev/disk2s1
    sudo dd bs=1M if='/path/to/file.img' of='/dev/rdisk2' conv=sync
  • Copy the current hard drive into an image

    # Exporting an SD card save
    sudo dd bs=4M if=/dev/sdb of=raspbian.img
    # Importing an SD card save
    sudo dd bs=4M if=raspbian.img of=/dev/sdb
  • Eject a device

    sudo diskutil eject /dev/rdisk2
  • Enable vpn connection on port 3340

    kill $(lsof -ti :3340) &> /dev/null
    ssh -fNCD 3340 'ssh://bastion@'
    networksetup -setsocksfirewallproxystate Wi-Fi on
    return 0
  • Disable vpn connection on port 3340

      kill $(lsof -ti :3340) &> /dev/null
      networksetup -setsocksfirewallproxystate Wi-Fi off
      return 0


New to macOS Catalina is the Books application, which provides a cleaner interface for handling audiobooks on your Mac.

  • Audiobooks are stored in ~/Library/Containers/