-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacos-configure.sh
executable file
·59 lines (51 loc) · 1.12 KB
/
macos-configure.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
#!/usr/bin/env bash
set -e
set -o pipefail
function echoErr {
echo "$1" 1>&2
}
# Verify and extract parameters
if [[ "$#" -ne 4 ]]
then
echoErr "Four input parameters required:"
echoErr " - type (string | integer | float | boolean)"
echoErr " - domain (e.g. com.apple.dock)"
echoErr " - key (e.g. autohide)"
echoErr " - value"
exit 1
fi
TYPE="$1"
DOMAIN="$2"
KEY="$3"
VALUE="$4"
# Check if the value has to be changed
CHANGED="false"
CURRENT_VALUE="$(defaults read "${DOMAIN}" "${KEY}" || echo -n "")"
if [[ "$TYPE" == "boolean" ]]
then
if [[ "$(echo ${VALUE} | tr "[:upper:]" "[:lower:]")" =~ ^(yes|true)$ ]]
then
VALUE_AS_INT="1"
elif [[ "$(echo ${VALUE} | tr "[:upper:]" "[:lower:]")" =~ ^(no|false)$ ]]
then
VALUE_AS_INT="0"
else
echoErr "Incorrect boolean value given"
exit 1
fi
if [[ "$VALUE_AS_INT" != "$CURRENT_VALUE" ]]
then
CHANGED="true"
fi
else
if [[ "$VALUE" != "$CURRENT_VALUE" ]]
then
CHANGED="true"
fi
fi
# Update the value if it has changed
if [[ "$CHANGED" == "true" ]]
then
defaults write "${DOMAIN}" "${KEY}" -${TYPE} "${VALUE}"
echo "changed"
fi