Last active
January 2, 2020 12:22
-
-
Save ZevEisenberg/8d2f2dc66c38898fa259 to your computer and use it in GitHub Desktop.
Keyboard Shortcut Shell Script Magic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addCustomMenuEntryIfNeeded | |
{ | |
if [[ $# == 0 || $# > 1 ]]; then | |
echo "usage: addCustomMenuEntryIfNeeded com.company.appname" | |
return 1 | |
else | |
local contents=`defaults read com.apple.universalaccess "com.apple.custommenu.apps"` | |
local grepResults=`echo $contents | grep $1` | |
if [[ -z $grepResults ]]; then | |
# does not contain app | |
defaults write com.apple.universalaccess "com.apple.custommenu.apps" -array-add "$1" | |
else | |
# contains app already, so do nothing | |
fi | |
fi | |
} | |
function fixKeyboardShortcuts | |
{ | |
local COMMAND_KEY_SYMBOL="@" | |
local CONTROL_KEY_SYMBOL="^" | |
local OPTION_KEY_SYMBOL="~" | |
local SHIFT_KEY_SYMBOL="$" | |
local TAB_KEY_SYMBOL="\\U21e5" | |
# Finder | |
# Show Package Contents: Command-Shift-O | |
defaults write com.apple.finder NSUserKeyEquivalents "{ 'Show Package Contents' = '${COMMAND_KEY_SYMBOL}${SHIFT_KEY_SYMBOL}O'; }" | |
addCustomMenuEntryIfNeeded "com.apple.finder" | |
# Terminal | |
# Select Next Tab: Control-Tab | |
# Select Previous Tab: Control-Shift-Tab | |
defaults write com.apple.Terminal NSUserKeyEquivalents "{ | |
'Select Next Tab' = '${CONTROL_KEY_SYMBOL}${TAB_KEY_SYMBOL}'; | |
'Select Previous Tab' = '${CONTROL_KEY_SYMBOL}${SHIFT_KEY_SYMBOL}${TAB_KEY_SYMBOL}'; | |
}" | |
addCustomMenuEntryIfNeeded "com.apple.Terminal" | |
# OmniGraffle | |
# Fit in Window: Command-0 | |
# Grid Lines: Option-Command-G | |
defaults write com.omnigroup.OmniGraffle6 NSUserKeyEquivalents "{ | |
'Fit in Window' = '${COMMAND_KEY_SYMBOL}0'; | |
'Grid Lines' = '${OPTION_KEY_SYMBOL}${COMMAND_KEY_SYMBOL}G'; | |
}" | |
addCustomMenuEntryIfNeeded "com.omnigroup.OmniGraffle6" | |
} | |
fixKeyboardShortcuts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment