{"id":873,"date":"2020-11-07T00:10:30","date_gmt":"2020-11-07T05:10:30","guid":{"rendered":"https:\/\/www.brunerd.com\/blog\/?p=873"},"modified":"2020-11-07T00:15:09","modified_gmt":"2020-11-07T05:15:09","slug":"jpt-jamf-examples-pt-2","status":"publish","type":"post","link":"https:\/\/www.brunerd.com\/blog\/2020\/11\/07\/jpt-jamf-examples-pt-2\/","title":{"rendered":"jpt: jamf examples pt. 2"},"content":{"rendered":"\n<p>Over in the MacAdmins&#8217; #bash channel I saw a I question regarding how to get the Sharing states of Bluetooth devices from system_profiler. The most succinct answer was to awk out the values:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>system_profiler SPBluetoothDataType 2> \/dev\/null | awk '\/State: \/ {print $2}'\nDisabled\nDisabled\nDisabled<\/code><\/pre>\n\n\n\n<p>If you are using this for a Jamf Extension Attribute, I suppose it&#8217;ll do if you never want to allow any of them to be Enabled, but what if Internet Sharing was OK but not File Sharing? How would you match your Smart Group to multiple lines of unlabeled values? How would you match the first two but not the last two&#8230; and what if there was another USB Bluetooth device, that would add extra rows. Hmmm&#8230;<\/p>\n\n\n\n<p>The answer for me, outputting the service name and the state on the same line. Since there isn&#8217;t a consistent line count from <code>State: <\/code>going back the service name,  using something like grep -B <em>n<\/em> to include <em>n<\/em> lines of preceding data <em>isn&#8217;t<\/em> going to work.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>      Services:\n          Bluetooth File Transfer:\n              Folder other devices can browse: ~\/Public\n              When receiving items: Accept all without warning\n              State: Disabled\n          Bluetooth File Exchange:\n              Folder for accepted items: ~\/Downloads\n              When other items are accepted: Save to location\n              When receiving items: Accept all without warning\n              State: Disabled\n          Bluetooth Internet Sharing:\n              State: Disabled\n<\/code><\/pre>\n\n\n\n<p>So you know what I say the answer to <em>that<\/em> is? That&#8217;s right, <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/brunerd\/jpt\" target=\"_blank\"><code>jpt<\/code> the JSON Power Tool<\/a>! It can parse the <code>-json<\/code> output from <code>system_profiler<\/code> in a more structured way and it allows for the discovery of as many applicable Bluetooth devices might be on the system.<\/p>\n\n\n\n<p><script src=\"https:\/\/gist.github.com\/brunerd\/b6a66c432876ef99298ad0acc3e62471.js\"><\/script><\/p>\n\n\n\n<p>Here&#8217;s a sample run with Internet Sharing turned On as well as Bluetooth Sharing turned On<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>file_browsing: disabled\nobject_push: enabled\ninternet_sharing: enabled<\/code><\/pre>\n\n\n\n<p>File Browsing is set to &#8220;Never Allow&#8221; but File Receiving is in the affirmative (Accept and Open, Accept and Save, or Ask). The addition of labels gives us the ability to create a Smart Group to match specific services like &#8220;file_browing: enabled&#8221; or any other combination thereof (perhaps internet_sharing should always be enabled, who am I to say what your requirements are!). <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">About the jpt<\/h4>\n\n\n\n<p>The JSON Power Tool (jpt) is a parser\/manipulator for JSON documents written in Javascript and shell and can run standalone or embedded in your scripts bash or zsh and all the way back to OS X 10.4 Tiger! Check it out at: <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/brunerd\/jpt\" target=\"_blank\">https:\/\/github.com\/brunerd\/jpt<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over in the MacAdmins&#8217; #bash channel I saw a I question regarding how to get the Sharing states of Bluetooth devices from system_profiler. The most succinct answer was to awk out the values: If you are using this for a Jamf Extension Attribute, I suppose it&#8217;ll do if you never want to allow any of [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,46,37,12,39],"tags":[],"class_list":["post-873","post","type-post","status-publish","format-standard","hentry","category-bash","category-jamf","category-jpt","category-scripting","category-zsh"],"_links":{"self":[{"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/posts\/873","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/comments?post=873"}],"version-history":[{"count":7,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/posts\/873\/revisions"}],"predecessor-version":[{"id":880,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/posts\/873\/revisions\/880"}],"wp:attachment":[{"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/media?parent=873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/categories?post=873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/tags?post=873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}