Last active
November 7, 2020 04:35
-
-
Save brunerd/b6a66c432876ef99298ad0acc3e62471 to your computer and use it in GitHub Desktop.
Report the states of Bluetooth Sharing services in macOS using jpt to parse JSON output from system_profiler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Joel Bruner | |
#BTSharingStateas - report bluetooth sharing states from system_profiler using jpt to parse output | |
#if jpt is not installed locally, embed function from jpt.min into this script: https://github.com/brunerd/jpt | |
#get all the data once | |
SPBluetooth=$(system_profiler -json SPBluetoothDataType 2>/dev/null) | |
#get the paths related to service state | |
statePaths=$(jpt -jd '$..service_state' <<< "${SPBluetooth}") | |
:<<STATEPATHS_SAMPLE | |
$.SPBluetoothDataType[0].services_title[0].file_browsing_title.service_state | |
$.SPBluetoothDataType[0].services_title[1].object_push_title.service_state | |
$.SPBluetoothDataType[0].services_title[2].internet_sharing_title.service_state | |
STATEPATHS_SAMPLE | |
#go through each path and report | |
IFS=$'\n' | |
for path in ${statePaths}; do | |
#strip out the service name and clean it up | |
serviceName=$(tr . $'\n' <<< "$path" | awk '/_title/ && !/services_title/ {print $1}' | sed 's/_title//') | |
#get the state and clean it up to: enabled/disabled | |
serviceState=$(jpt -T "${path}" <<< "${SPBluetooth}" | sed 's/attrib_//') | |
echo "${serviceName}: ${serviceState}" | |
done | |
#Turn on Intenet and Bluetooth Sharing to test for enablement | |
:<<OUTPUT_SAMPLE | |
file_browsing: enabled | |
object_push: enabled | |
internet_sharing: disabled | |
OUTPUT_SAMPLE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment