Repository navigation
Expand file tree
/
Copy pathdefaults-write.sh
More file actions
executable file
·66 lines (45 loc) · 1.48 KB
/
Copy pathdefaults-write.sh
File metadata and controls
executable file
·66 lines (45 loc) · 1.48 KB
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
#!/bin/bash
# author: Jon Christensen, date: 2019-05-25, macOS: 10.14.4, GitHub / Jamf Nation: jychri
# --- set value(s) here --- #
plist=""
if [ "$4" != "" ] && [ "$plist" == "" ]; then
plist=$4
fi
key=""
if [ "$5" != "" ] && [ "$key" == "" ]; then
key=$5
fi
value=""
if [ "$6" != "" ] && [ "$value" == "" ]; then
value=$6
fi
# --- do not edit below --- #
function defaultsWrite() {
if [ -z "$1" ]; then
echo "plistWrite => [exit 1] no plist argument passed"; exit 1
fi
if [ -z "$2" ]; then
echo "plistWrite => [exit 1] no key argument passed"; exit 1
fi
if [ -z "$3" ]; then
echo "plistWrite => [exit 1] no value argument passed"; exit 1
fi
local plist; plist="$1"
local key; key="$2"
local value; value="$3"
echo "plistWrite: checking the initial value for '$key' in '$plist'"
local defaults; defaults="/usr/bin/defaults"
local pbuddy; pbuddy="/usr/libexec/PlistBuddy"
local init_value; init_value=$($pbuddy -c print ":$key" "$plist")
echo "plistWrite: initial value is '$init_value' for '$key' in '$plist'";
echo "plistWrite: writing value '$value' for '$key' in '$plist'";
$defaults write "$plist" "$key" "$value"
local final_value; final_value=$($pbuddy -c print ":$key" "$plist")
if [ "$value" == "$final_value" ]; then
echo "plistWrite: confirmed '$value' for '$key' in '$plist'"; exit 1
else
echo "plistWrite => [exit 1] '$value' != '$final_value'"; exit 1
fi
}
# --- main! --- #
defaultsWrite "$plist" "$key" "$value"