├── OneLiner.sh ├── README.md ├── AirPodsPower.sh └── LICENSE /OneLiner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | OUTPUT='🎧'; BLUETOOTH_DEFAULTS=$(defaults read /Library/Preferences/com.apple.Bluetooth); SYSTEM_PROFILER=$(system_profiler SPBluetoothDataType 2>/dev/null); MAC_ADDR=$(grep -b2 "Minor Type: Headphones"<<<"${SYSTEM_PROFILER}"|awk '/Address/{print $3}'); CONNECTED=$(grep -ia6 "${MAC_ADDR}"<<<"${SYSTEM_PROFILER}"|awk '/Connected: Yes/{print 1}'); BLUETOOTH_DATA=$(grep -ia6 '"'"${MAC_ADDR}"'"'<<<"${BLUETOOTH_DEFAULTS}"); BATTERY_LEVELS=("BatteryPercentCombined" "HeadsetBattery" "BatteryPercentSingle" "BatteryPercentCase" "BatteryPercentLeft" "BatteryPercentRight"); if [[ "${CONNECTED}" ]]; then for I in "${BATTERY_LEVELS[@]}"; do declare -x "${I}"="$(awk -v pat="${I}" '$0~pat{gsub (";",""); print $3 }'<<<"${BLUETOOTH_DATA}")"; [[ ! -z "${!I}" ]] && OUTPUT="${OUTPUT} $(awk '/BatteryPercent/{print substr($0,15,1)": "}'<<<"${I}")${!I}%"; done; printf "%s\\n" "${OUTPUT}"; else printf "%s Not Connected\\n" "${OUTPUT}"; fi 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AirPods Battery CLI 2.3 2 | ## Copyright 2017 Dustin Kerr & Daniel Jones, All Rights Reserved. 3 | ## Released under the MIT License. 4 | 5 | 6 | ### About 7 | This is a CLI tool for Grabbing the AirPods Battery Status 8 | 9 | Information is collected from defaults read /Library/Preferences/com.apple.Bluetooth to grab Battery Info from a pair of connected AirPods. It will currently only grab the info for the first paired set of W1 supported headphones. 10 | 11 | ### Usage 12 | 13 | If you have multiple sets of Headphones, you can change the line that reads: 14 | 15 | MAC_ADDR=$(grep -b2 "Minor Type: Headphones"<<<"${SYSTEM_PROFILER}"|awk '/Address/{print $3}') 16 | 17 | To match the MAC address of heaphones you want info for: 18 | 19 | MAC_ADDR="7c-04-d0-af-88-62" 20 | 21 | ### Guide 22 | 23 | There is a bigger usage guide available online at: 24 | http://blog.duklabs.com/airpods-power-in-touchbar/ 25 | 26 | ### Requirements 27 | 28 | This has been tested and works on OSX 10.12.6 and above. 29 | -------------------------------------------------------------------------------- /AirPodsPower.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # AirPods Battery CLI, Version 2.3 3 | # Contributors: duk242, ankushg, spetykowski, danozdotnet 4 | # Released under the MIT License. 5 | 6 | OUTPUT='🎧'; BLUETOOTH_DEFAULTS=$(defaults read /Library/Preferences/com.apple.Bluetooth); SYSTEM_PROFILER=$(system_profiler SPBluetoothDataType 2>/dev/null) 7 | MAC_ADDR=$(grep -b2 "Minor Type: Headphones"<<<"${SYSTEM_PROFILER}"|awk '/Address/{print $3}') 8 | CONNECTED=$(grep -ia6 "${MAC_ADDR}"<<<"${SYSTEM_PROFILER}"|awk '/Connected: Yes/{print 1}') 9 | BLUETOOTH_DATA=$(grep -ia6 '"'"${MAC_ADDR}"'"'<<<"${BLUETOOTH_DEFAULTS}") 10 | BATTERY_LEVELS=("BatteryPercentCombined" "HeadsetBattery" "BatteryPercentSingle" "BatteryPercentCase" "BatteryPercentLeft" "BatteryPercentRight") 11 | 12 | if [[ "${CONNECTED}" ]]; then 13 | for I in "${BATTERY_LEVELS[@]}"; do 14 | declare -x "${I}"="$(awk -v pat="${I}" '$0~pat{gsub (";",""); print $3 }'<<<"${BLUETOOTH_DATA}")" 15 | [[ ! -z "${!I}" ]] && OUTPUT="${OUTPUT} $(awk '/BatteryPercent/{print substr($0,15,1)": "}'<<<"${I}")${!I}%" 16 | done 17 | printf "%s\\n" "${OUTPUT}" 18 | else 19 | printf "%s Not Connected\\n" "${OUTPUT}" 20 | fi 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Dustin Kerr, and Daniel Jones 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------