Skip to content

Instantly share code, notes, and snippets.

@usagimaru
Last active August 24, 2023 10:31
Show Gist options
  • Save usagimaru/dd16ba83608fabf98bf842e277c65fd7 to your computer and use it in GitHub Desktop.
Save usagimaru/dd16ba83608fabf98bf842e277c65fd7 to your computer and use it in GitHub Desktop.
Disable any keyboard shortcuts of the specific app on macOS.

Disable any keyboard shortcuts of the specific app on macOS

Shell Script

#!/bin/sh

defaults write com.bohemiancoding.sketch3 NSUserKeyEquivalents '{
"Show Prototyping"=" ";
"Show Slices"=" ";
"Show Layout"=" ";
"Show Pixels on Zoom"=" ";
"Show Rulers"=" ";
"Show Grid"=" ";
"Pick Color"=" ";
"Select Parent"=" ";
"Clear Selection"=" ";
"Return to Instance"=" ";
}'

# All values are NO-BREAK SPACE (U+00A0)
# To disable a shortcut, assign a character such as NO-BREAK SPACE (U+00A0) and ZERO WIDTH SPACE (U+200B) to the value.

概要

DefaultKeyBinding.dictと同じ形式でキーボードショートカットを表す。

@ : ⌘ Command
~ : ⌥ Option
^ : ^ Control
$ : ⇧ Shift

キーボードショートカットの無効化には、NO-BREAK SPACE (U+00A0) や ZERO WIDTH SPACE (U+200B) などを割り当てると良い。NO-BREAK SPACE (U+00A0) の方が文字の存在を可視化しやすいので、こちらがおすすめ。
空文字や通常の SPACE (U+0020) では無効化されないので注意。

アプリケーションを指定せず、すべてを対象にする

NSGlobalDomainを対象に実行すれば良い。

defaults write -g NSUserKeyEquivalents …

または

defaults write NSGlobalDomain NSUserKeyEquivalents …

現在のカスタマイズされた設定をすべて表示

% defaults find NSUserKeyEquivalents

キーボードショートカット設定の保存先

環境設定を収録した各plistファイル内に NSUserKeyEquivalents をキーとして辞書形式で追記される。

~/Library/Preferences/com.bohemiancoding.sketch3

アプリケーション全体は .GlobalPreferences.plist 内。

~/Library/Preferences/.GlobalPreferences.plist

サービスメニューのショートカットは pbs.plist 内。

~/Library/Preferences/pbs.plist.

参考資料

https://apple.stackexchange.com/questions/123382/is-there-a-way-to-save-your-custom-keyboard-shortcuts-in-a-config-file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment