-
Notifications
You must be signed in to change notification settings - Fork 27
/
us_layout_remover.sh
53 lines (43 loc) · 1.27 KB
/
us_layout_remover.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
#!/bin/bash
# Evgeny Stepanischev Aug 2012 http://bolknote.ru
# http://artpolikarpov.ru/2012/08/24/1/
PLIST=~/Library/Preferences/ByHost/com.apple.HIToolbox.*.plist
BACKUP=$(echo $PLIST).backup
function GetSection {
/usr/libexec/PlistBuddy -c "Print :$1" $PLIST
}
function WhereUS {
local num=0
GetSection "$1" |
while read -r -d} line; do
if echo "$line" | grep -Fq U.S.; then
echo $num
break
fi
let 'num++'
done
}
function DeleteFromSection {
[ -n "$2" ] || return
/usr/libexec/PlistBuddy -c "Delete :$1:$2 dict" $PLIST
}
# Смотрим, не было ли бакапа
if [ -e $BACKUP ]; then
mv -f $BACKUP $PLIST
echo Restored.
else
# если не было, сохраняем исходный файл
if cp $PLIST $BACKUP; then
# удаляем упоминание о раскладке US изо всех секций
/usr/libexec/PlistBuddy -c Print $PLIST | awk '/Array {/ {print $1}' |
while read field; do
DeleteFromSection $field `WhereUS $field`
done
echo Removed.
else
echo Error: cannot backup file. Exiting.
exit 1
fi
fi
echo Try to logout.
osascript -e 'tell application "System Events" to log out'