{"id":6,"date":"2006-05-30T18:04:45","date_gmt":"2006-05-31T01:04:45","guid":{"rendered":"http:\/\/www.dreness.com\/blog\/archives\/6"},"modified":"2006-05-31T22:13:22","modified_gmt":"2006-06-01T05:13:22","slug":"modifying-nested-property-list-items-with-plistbuddy","status":"publish","type":"post","link":"https:\/\/dreness.com\/blog\/archives\/6","title":{"rendered":"Modifying nested property list items with PlistBuddy"},"content":{"rendered":"<p>The \/usr\/bin\/defaults command gives us basic command line access to the Mac OS X preferences system. I say &#8216;basic&#8217; because it provides no facility for directly operating on any keys \/ values that are not at the top of the heirarchy. For example:<\/p>\n<pre>\r\n{8} andre@werk [~] % defaults read com.apple.finder ComputerOptions\r\n{\r\n    ComputerListViewColumnFlags = 1; \r\n    ComputerSidebarWidth = 121; \r\n    ComputerToolbarVisible = 0; \r\n    ComputerUseCustomIconViewOptions = 1; \r\n    ComputerUseCustomListViewOptions = 1; \r\n    ComputerViewHeight = 385; \r\n    ComputerViewStyle = clmv; \r\n    ComputerWindowBounds = {bottom = 726; left = 1589; right = 2277; top = 341; }; \r\n}\r\n<\/pre>\n<p>The ComputerOptions key contains not a string or an integer, but a dict (dictionary). Note that this is different from a &#8216;top level&#8217; key which is a simple key \/ value relationship, such as:<\/p>\n<pre>\r\n{9} andre@werk [~] % defaults read com.apple.finder AppleShowAllFiles\r\nOFF\r\n<\/pre>\n<p>So, what do you do when you want to change the value of, for example, the ComputerToolbarVisible attribute in the ComputerOptions dict? With \/usr\/bin\/defaults, you&#8217;d have to read out the entire dictionary, make the change in some other mutable environment, then load the whole ComputerOptions dict back in as a plist. It works, but there&#8217;s an easier way, using a tool that&#8217;s already on your system: PlistBuddy. You&#8217;ll find this in several apple-supplied installer packages (on my system at work, I have 18 different copies of PlistBuddy scattered throughout various packages \/ receipts).<\/p>\n<p>Here&#8217;s how you&#8217;d twiddle the ComputerToolbarVisible attribute with PlistBuddy. Note that this is all one single command.<\/p>\n<pre>\/Library\/Receipts\/AdditionalEssentials.pkg\/Contents\/Resources\/PlistBuddy -c \\\\\r\n\"set ComputerOptions:ComputerToolbarVisible 1\" \\\\\r\n~\/Library\/Preferences\/com.apple.finder.plist<\/pre>\n<p>and then check the results&#8230;<\/p>\n<pre>{14} andre@werk [~] % defaults read com.apple.finder ComputerOptions | grep Toolbar        \r\n    ComputerToolbarVisible = 1; <\/pre>\n<p>Execute PlistBuddy with no arguments, and then again with -h for more information.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The \/usr\/bin\/defaults command gives us basic command line access to the Mac OS X preferences system. I say &#8216;basic&#8217; because it provides no facility for directly operating on any keys \/ values that are not at the top of the &hellip; <a href=\"https:\/\/dreness.com\/blog\/archives\/6\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-6","post","type-post","status-publish","format-standard","hentry","category-os-x"],"_links":{"self":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts\/6","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/comments?post=6"}],"version-history":[{"count":0,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts\/6\/revisions"}],"wp:attachment":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/media?parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/categories?post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/tags?post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}