Macのシステム環境設定から設定できるキーボードショートカットをコマンドラインで設定する方法を紹介します。
他のMacでも同じ設定を追加したい場合などに便利です。
ターミナルからdefaultsコマンドを実行して設定していきます。
アプリケーションごとにKeyが異なり、またアプリケーションごとに動作を確認する必要があるため、全アプリケーション一括で設定ではなく、個別に設定しています。
### Atom
defaults write com.github.atom NSUserKeyEquivalents -dict-add "Paste" -string "^v"
defaults write com.github.atom NSUserKeyEquivalents -dict-add "Close Tab" -string "^w"
defaults write com.github.atom NSUserKeyEquivalents -dict-add "New Tab" -string "^t"
defaults write com.github.atom NSUserKeyEquivalents -dict-add "Save" -string "^s"
defaults write com.github.atom NSUserKeyEquivalents -dict-add "Cut" -string "^x"
defaults write com.github.atom NSUserKeyEquivalents -dict-add "Undo" -string "^z"
### Google Chrome
defaults write com.google.Chrome NSUserKeyEquivalents -dict-add "Close Tab" -string "^w"
defaults write com.google.Chrome NSUserKeyEquivalents -dict-add "Copy" -string "^c"
defaults write com.google.Chrome NSUserKeyEquivalents -dict-add "New Tab" -string "^t"
defaults write com.google.Chrome NSUserKeyEquivalents -dict-add "Open Location..." -string "^l"
defaults write com.google.Chrome NSUserKeyEquivalents -dict-add "Paste" -string "^v"
defaults write com.google.Chrome NSUserKeyEquivalents -dict-add "Quit Google Chrome" -string "^q"
defaults write com.google.Chrome NSUserKeyEquivalents -dict-add "Reload This Page" -string "^r"
defaults write com.google.Chrome NSUserKeyEquivalents -dict-add "Undo" -string "^z"
### Safari
defaults write com.apple.safari NSUserKeyEquivalents -dict-add "Close Tab" -string "^w"
defaults write com.apple.safari NSUserKeyEquivalents -dict-add "Copy" -string "^c"
defaults write com.apple.safari NSUserKeyEquivalents -dict-add "Find..." -string "^f"
defaults write com.apple.safari NSUserKeyEquivalents -dict-add "New Tab" -string "^t"
defaults write com.apple.safari NSUserKeyEquivalents -dict-add "Open Location..." -string "^l"
defaults write com.apple.safari NSUserKeyEquivalents -dict-add "Paste" -string "^v"
defaults write com.apple.safari NSUserKeyEquivalents -dict-add "Quit Safari" -string "^q"
defaults write com.apple.safari NSUserKeyEquivalents -dict-add "Reload This Page" -string "^r"
defaults write com.apple.safari NSUserKeyEquivalents -dict-add "Undo" -string "^z"
### Finder
defaults write com.apple.safari NSUserKeyEquivalents -dict-add "New Finder Window" -string "^w"
defaults write com.apple.safari NSUserKeyEquivalents -dict-add "Close Window" -string "^w"
### Evernote
defaults write com.evernote.Evernote NSUserKeyEquivalents -dict-add "New Notebook" -string "^$n"
defaults write com.evernote.Evernote NSUserKeyEquivalents -dict-add "Quit Evernote" -string "^q"
defaults write com.evernote.Evernote NSUserKeyEquivalents -dict-add "Select All" -string "^a"
### Excel
defaults write com.microsoft.Excel NSUserKeyEquivalents -dict-add "Save" -string "^s"
### twitter
defaults write maccatalyst.com.atebits.Tweetie2 NSUserKeyEquivalents -dict-add "Close" -string "^w"
defaults write maccatalyst.com.atebits.Tweetie2 NSUserKeyEquivalents -dict-add "Copy" -string "^c"
defaults write maccatalyst.com.atebits.Tweetie2 NSUserKeyEquivalents -dict-add "Cut" -string "^x"
defaults write maccatalyst.com.atebits.Tweetie2 NSUserKeyEquivalents -dict-add "New Tweet" -string "^n"
defaults write maccatalyst.com.atebits.Tweetie2 NSUserKeyEquivalents -dict-add "Paste" -string "^v"
defaults write maccatalyst.com.atebits.Tweetie2 NSUserKeyEquivalents -dict-add "Quit Twitter" -string "^q"
defaults write maccatalyst.com.atebits.Tweetie2 NSUserKeyEquivalents -dict-add "Reply" -string "^r"
### Keychain
defaults write com.apple.keychainaccess NSUserKeyEquivalents -dict-add "Copy" -string "^c"
defaults write com.apple.keychainaccess NSUserKeyEquivalents -dict-add "Paste" -string "^v"
### Mail
defaults write com.apple.mail NSUserKeyEquivalents -dict-add "Copy" -string "^c"
defaults write com.apple.mail NSUserKeyEquivalents -dict-add "Paste" -string "^v"
defaults write com.apple.mail NSUserKeyEquivalents -dict-add "Quit Mail" -string "^q"
defaults write com.apple.mail NSUserKeyEquivalents -dict-add "Close" -string "^w"
### Finder
defaults write com.apple.Finder NSUserKeyEquivalents -dict-add "Move to Trash" -string "^d
この設定はアプリケーション再起動後じゃないと反映されないので、ご注意ください。
あと、バックスラッシュを含むショートカットは、バックスラッシュが複数挿入されてしまい、うまくいきません。
なお、新しくアプリケーションを追加したい場合は、システム環境設定からひとつショートカットを追加して、defaults domains
コマンドを用いてアプリケーションのドメイン名を確認します。
(ショートカットを事前に追加する理由は、少なくとも1つはショートカットを設定していないと、ドメイン名が表示されないためです。)