-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmacos-keybindings.sh
executable file
·68 lines (63 loc) · 2.34 KB
/
macos-keybindings.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
set -eu
echo "# NSUserKeyEquivalents utility"
select mode in Backup Restore; do
case $mode in
Backup)
# find all Preferences domains that have NSUserKeyEquivalents defined
domains=(
-globalDomain
$(
defaults find NSUserKeyEquivalents |
sed '
/^Found .* keys in domain/!d
s/.*'\''\([^'\'']*\)'\''.*/\1/
' |
sort
))
# generate shell commands for every menu-keybinding entry
for domain in "${domains[@]}"; do
defaults read "$domain" NSUserKeyEquivalents |
sed '
/".*" = ".*";/!d
s/.*"\([^"]*\)".*=.*"\([^"]*\)";/"\1" '\''\2'\''/
s/^/NSUserKeyEquivalents '\'$domain\'' /
'
done |
# replace what's at the bottom of this script
sed -e '1,/^########*$/!d' -e '/^########*$/r /dev/stdin' -i~ "$0"
exit
;;
Restore)
break
;;
*)
esac
done
NSUserKeyEquivalents() {
local domain=$1
local menu=$2 key=$3
while read -p "Update $domain's keyboard shortcut for \"$menu\" to $key? [y/N] " -n 1 -s; echo $REPLY; do
case $REPLY in
[yY])
(set -x
defaults write "$domain" NSUserKeyEquivalents \
-dict-add "$menu" "$key"
)
break
;;
[nN]) break ;;
esac
done
}
################################################################################
NSUserKeyEquivalents 'com.apple.Preview' "Move To..." '@$m'
NSUserKeyEquivalents 'com.apple.Terminal' "Select Next Tab" '^\\U21e5'
NSUserKeyEquivalents 'com.apple.Terminal' "Select Previous Tab" '^$\\U21e5'
NSUserKeyEquivalents 'com.google.Chrome' "Pin Tab" '@$p'
NSUserKeyEquivalents 'com.google.Chrome' "Quit Google Chrome" '~q'
NSUserKeyEquivalents 'com.omnigroup.OmniFocus3.MacAppStore' "New Folder" '@$n'
NSUserKeyEquivalents 'com.omnigroup.OmniFocus3.MacAppStore' "Quit OmniFocus" '@$q'
NSUserKeyEquivalents 'com.omnigroup.OmniFocus3.MacAppStore' "Search Here" '@p'
NSUserKeyEquivalents 'com.sublimetext.3' "Hide Sublime Text" '@~^$h'
NSUserKeyEquivalents 'com.sublimetext.3' "Quit Sublime Text" '@^q'