diff options
-rw-r--r-- | cspell.json | 1 | ||||
-rw-r--r-- | lib/chef/resource/macos_userdefaults.rb | 17 |
2 files changed, 11 insertions, 7 deletions
diff --git a/cspell.json b/cspell.json index 6d661c83b8..e70f7cf460 100644 --- a/cspell.json +++ b/cspell.json @@ -1119,7 +1119,6 @@ "dracut", "dragonflybsd", "dragonsmith", - "drcmd", "drzewiec", "dscacheutil", "dscl", diff --git a/lib/chef/resource/macos_userdefaults.rb b/lib/chef/resource/macos_userdefaults.rb index a8158aba5e..df9c20f45a 100644 --- a/lib/chef/resource/macos_userdefaults.rb +++ b/lib/chef/resource/macos_userdefaults.rb @@ -74,12 +74,17 @@ class Chef load_current_value do |desired| value = coerce_booleans(desired.value) - drcmd = "defaults read '#{desired.domain}' " - drcmd << "'#{desired.key}' " if desired.key - shell_out_opts = {} - shell_out_opts[:user] = desired.user unless desired.user.nil? - vc = shell_out("#{drcmd} | grep -qx '#{value}'", shell_out_opts) - is_set vc.exitstatus == 0 ? true : false + cmd = "defaults read '#{desired.domain}' " + cmd << "'#{desired.key}' " if desired.key + cmd << " | grep -qx '#{value}'" + + vc = if desired.user.nil? + shell_out(cmd) + else + shell_out(cmd, user: desired.user) + end + + is_set vc.exitstatus == 0 end action :write do |