John Siu Blog

Tech - Business Tool, Personal Toys

MacOS Command Line

☰ Table of Content

Some MacOS commands and keyboard shortcuts.

Keyboard Shortcut

ShortcutDescription
Command+. or escClick cancel in dialog
Command+dClick Don't Save in dialog
Command+tabSwitch app
Command+mMinimize app
Command+hHide app (not minimize)
Command+`Switch window of the same app
Command+,Open preference of most app
Command+wClose active tab of an app
Command+qClose active app
Command+bToggle sidebar in app
Command+option+left/rightSwitch tab in app
Command+shift+.Show hidden file in finder

Desktop Space

ShortcutDescription
Ctrl+Up ArrowSelect space
Ctrl+Down ArrowReturn to desktop

Un-minimize

ShortcutDescription
Command+tab -> (do not release Command) -> Command+option+returnUn-minimize app

Run Application from Command Line

Application name is case-sensitive. Use tab for auto-complete.

1
2
open -a <application>
open -a Google\ Earth\ Pro

Launch Control

  • List all services

    1
    2
    3
    
    launchctl list # List services
    launchctl load <plist file> # Start service
    launchctl unload <plist file> # Stop service
    
  • List all 3rd-party(non-Apple) services

    1
    
    launchctl list|grep -v com.apple.
    
  • System Service Location

    • /Library/LaunchDaemons/
    • /System/Library/LaunchDaemons/

Memory Usage

Result is in page number. Multiply with page size show at the top.

1
vm_stat

Kernel Extension

  • List all kernel extension

    1
    
    kextstat
    
  • List all non-Apple extension

    1
    
    kextstat | grep -v com.apple
    

Plist Content

1
plutil -p <file>

Safe Mode

Hold down Shift during boot.

Command line may not work anymore.

  • Enable

    1
    2
    
    sudo nvram boot-args="-x"
    sudo nvram boot-args="-x -v"
    
  • Disable

    1
    
    sudo nvram boot-args=""
    

Network Setup Command

  • Help

    1
    
    networksetup
    
  • List all network service

    1
    
    networksetup -listallnetworkservices
    
  • Turn network service on/off

    1
    2
    3
    
    networksetup -setnetworkserviceenabled <networkservice> <on off>
    networksetup -setnetworkserviceenabled Ethernet off
    networksetup -setnetworkserviceenabled Ethernet on
    

Change Hostname

1
sudo scutil --set HostName <hostname>

Mouse Speed

  • Get

    1
    
    defaults read -g com.apple.mouse.scaling
    
  • Set

    May need reboot.

    1
    
    defaults write -g com.apple.mouse.scaling your_mouse_speed
    

dns-sd (mdns/avahi/bonjour)

Get address of hostname

1
dns-sd -G v4v6 <hostname>

Play Audio

1
afplay <file>

John Siu

Update: 2023-07-12
comments powered by Disqus