Skip to content
This repository has been archived by the owner on Nov 6, 2018. It is now read-only.

Commit

Permalink
Merge pull request #10 from patcon/resource-attr-user
Browse files Browse the repository at this point in the history
Add `user` resource attr to `mac_os_x_userdefaults`
  • Loading branch information
Joshua Timberman committed Jan 27, 2013
2 parents e0fc88f + 4dad5cb commit 554ce45
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Manage the Mac OS X user defaults(1) system. The parameters to the resource are
- key: The preference key. Required.
- value: The value of the key. Required.
- type: Value type of the preference key.
- user: User for which to set the default.
- sudo: Set to true if the setting requires privileged access to modify. Default false.

`value` settings of `1`, `TRUE`, `true`, `YES` or `yes` are treated as true by defaults(1), and are handled in the provider.
Expand Down
8 changes: 6 additions & 2 deletions providers/userdefaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def load_current_resource
drcmd = "defaults read #{new_resource.domain} "
drcmd << "-g " if new_resource.global
drcmd << "#{new_resource.key} " if new_resource.key
v = shell_out("#{drcmd} | grep -qx '#{truefalse || new_resource.value}'")
shell_out_opts = {}
shell_out_opts[:user] = new_resource.user unless new_resource.user.nil?
v = shell_out("#{drcmd} | grep -qx '#{truefalse || new_resource.value}'", shell_out_opts)
is_set = v.exitstatus == 0 ? true : false
@userdefaults.is_set(is_set)
end
Expand Down Expand Up @@ -67,7 +69,9 @@ def load_current_resource

cmd << "-#{type}" if type
cmd << value
execute cmd.join(' ')
execute cmd.join(' ') do
user new_resource.user unless new_resource.user.nil?
end
new_resource.updated_by_last_action(true)
end
end
1 change: 1 addition & 0 deletions resources/userdefaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
attribute :key, :kind_of => String, :default => nil
attribute :value, :kind_of => [Integer,Float,String,TrueClass,FalseClass,Hash], :default => nil, :required => true
attribute :type, :kind_of => String, :default => nil
attribute :user, :kind_of => String, :default => nil
attribute :sudo, :kind_of => [TrueClass, FalseClass], :default => false
attribute :is_set, :kind_of => [TrueClass, FalseClass], :default => false

Expand Down

0 comments on commit 554ce45

Please sign in to comment.