Skip to content

Commit b33ec30

Browse files
committed
Improves output handling
1 parent 6e1c5ac commit b33ec30

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

src/user-defaults

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
binDefaults="/usr/bin/defaults"
66
binReload="/System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings"
7-
version="1.0"
7+
version="1.0.1"
88

99
## endregion ########################################### End Static Variables
1010

@@ -118,10 +118,12 @@ done
118118
prefix="sudo -u $targetUser"
119119
action="${args[0]}"
120120

121+
# Determine if this will write
122+
if echo "$action" | grep -q 'write\|array\|array-add\|dict\|dict-add'; then
123+
isWrite=true
124+
fi
125+
121126
if [ "$action" == "write" ] && $isSingle; then
122-
# Get Particulars
123-
domain="${args[1]}"
124-
key="${args[2]}"
125127
if $isType; then
126128
type="${args[3]}"
127129
value="${args[4]}"
@@ -159,23 +161,22 @@ done
159161

160162
# Output if Applicable
161163
if $isQuiet; then
162-
if $commandStr /dev/null 2>&1; then
163-
if echo "$action" | grep -q 'write\|array\|array-add\|dict\|dict-add'; then
164-
$prefix $binReload -u
165-
fi
166-
167-
exit 0
164+
if $isWrite; then
165+
$commandStr /dev/null 2>&1
166+
else
167+
$commandStr 2> /dev/null
168168
fi
169+
exitCode=$?
169170
else
170-
if $commandStr; then
171-
if echo "$action" | grep -q 'write\|array\|array-add\|dict\|dict-add'; then
172-
$prefix $binReload -u
173-
fi
171+
$commandStr
172+
exitCode=$?
173+
fi
174174

175-
exit 0
176-
else
177-
exit $?
178-
fi
175+
if [ "$exitCode" -eq "0" ] && $isWrite && [ -f "$binReload" ]; then
176+
# Reload preferences
177+
$prefix $binReload -u
179178
fi
180179

180+
exit "$exitCode"
181+
181182
## endregion ########################################### End Main Code

0 commit comments

Comments
 (0)