{"id":29185,"date":"2020-06-09T15:23:25","date_gmt":"2020-06-09T19:23:25","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=29185"},"modified":"2023-04-27T09:18:41","modified_gmt":"2023-04-27T13:18:41","slug":"plutil-enhanced-in-catalina","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2020\/06\/09\/plutil-enhanced-in-catalina\/","title":{"rendered":"plutil Enhanced in Catalina"},"content":{"rendered":"<p><a href=\"https:\/\/twitter.com\/monkeydom\/status\/1269411950104121345\">Dominik Wagner<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/monkeydom\/status\/1269411950104121345\">\n<p>TIL: plutil in catalina also supports objc and swift as output format. So if you want to quickly convert a e.g. json to inline code format, plutil might be the thing for you.<\/p>\n<\/blockquote>\n<p>Previously, <code>plutil<\/code> was mostly useful for validating propery lists and for converting between XML, binary, and JSON representations. Now it can also generate Objective-C and Swift literals. And there are new commands for inserting, replacing, removing, and extracting a value at a particular key path. This seems less powerful than <code>PlistBuddy<\/code> but with a more standard interface.<\/p>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2012\/08\/03\/mountain-lion-settings\/\">Mountain Lion Settings<\/a><\/li>\n<\/ul>\n\n<p id=\"plutil-enhanced-in-catalina-update-2021-01-12\">Update (2021-01-12): Unfortunately, <code>plutil<\/code> will crash if you try to set the value of a dictionary key whose first character is a number.<\/p>\n\n<p id=\"plutil-enhanced-in-catalina-update-2023-04-27\">Update (2023-04-27): <a href=\"https:\/\/derflounder.wordpress.com\/2023\/04\/15\/using-the-plutil-command-line-tool-to-work-with-json-on-macos-monterey-and-later\/\">Rich Trouton<\/a>:<\/p>\n<blockquote cite=\"https:\/\/derflounder.wordpress.com\/2023\/04\/15\/using-the-plutil-command-line-tool-to-work-with-json-on-macos-monterey-and-later\/\">\n<p>If you want to read JSON values from a file, you can use the <strong>raw<\/strong> option of <strong>plutil<\/strong>&rsquo;s <strong>-extract<\/strong> function in some cases to extract values from keys in JSON files.<\/p>\n<p>[&#8230;]<\/p>\n<p>In cases like this, where you&rsquo;re dealing with a JSON file with a fairly simple format (without arrays or otherwise nested values), <strong>plutil<\/strong> is a good tool which is built into macOS that you can call on to extract the data you need.<\/p>\n<p>Another option is using the <strong>plutil<\/strong> tool to write what you need to an XML file, then use <strong>plutil<\/strong>&rsquo;s <strong>-convert<\/strong> functionality to turn it into a JSON file. For folks more experienced with using <strong>plutil<\/strong> to write XML to a file than they are with writing JSON, this option may help with a lot of use cases.<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/01\/03\/jq-and-xmlstarlet\/\">jq and XmlStarlet<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Dominik Wagner: TIL: plutil in catalina also supports objc and swift as output format. So if you want to quickly convert a e.g. json to inline code format, plutil might be the thing for you. Previously, plutil was mostly useful for validating propery lists and for converting between XML, binary, and JSON representations. Now it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2020-06-09T19:23:29Z","apple_news_api_id":"f01a9026-dc30-4996-acb4-b7a23c409b9a","apple_news_api_modified_at":"2023-04-27T13:18:44Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAg==","apple_news_api_share_url":"https:\/\/apple.news\/A8BqQJtwwSZastLeiPECbmg","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[2],"tags":[131,75,507,30,1666,54,71,901,866],"class_list":["post-29185","post","type-post","status-publish","format-standard","hentry","category-technology","tag-bug","tag-developertool","tag-json","tag-mac","tag-macos-10-15","tag-objective-c","tag-programming","tag-swift-programming-language","tag-xml"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/29185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=29185"}],"version-history":[{"count":3,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/29185\/revisions"}],"predecessor-version":[{"id":39192,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/29185\/revisions\/39192"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=29185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=29185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=29185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}