I get the battery script working, but the 1.2 version will not keep the AirPods name - always asks again for it
EDIT:
I could edit the catalina.json script and it connects and disconnects - but I don't get the icon. It shows shortly and than ist gone :-(( Please help
I have honestly no clue why this doesn't work out for @tosbsas! I just downloaded the 1.2 version again and it works fine here!
I changed the script a little bit with that version, maybe try to copy-paste the attached script and replace the one of your widget (the widget script itself, not the associated action):
return checkStatus()
on checkStatus()
--GET STORED NAME
tell application "BetterTouchTool"
--attempt to get variable
try
set LclAirPodsName to get_string_variable "AirPodsWg_DevceName"
end try
end tell
--END GET STORED NAME
--set myString to button returned of (display dialog "Connected?" buttons {"Yes", "No"})
--set myString to "name: DR-BT101 Connected: " & myString
(*uncomment line below when done testing*)
set myString to do shell script "system_profiler SPBluetoothDataType"
--initial check if it's not even there
if myString does not contain LclAirPodsName then
return " "
else
--find out if connected/disconnected
set AppleScript's text item delimiters to "name:"
set myList to the text items of myString --each item of mylist is now one of the devices
set numberOfDevices to count of myList
set counter to 1
repeat numberOfDevices times --loop through each devices checking for Connected string
if item counter of myList contains LclAirPodsName then
if item counter of myList contains "Connected: Yes" then
return checkBattery()
else if item counter of myList contains "Connected: No" then
return " "
else
display dialog "Error Parsing" --this shouldn't happen
end if
end if
set counter to counter + 1
end repeat
end if
end checkStatus
on checkBattery()
set OUTPUT1 to do shell script "
OUTPUT1='';
BLUETOOTH_DEFAULTS=$(defaults read /Library/Preferences/com.apple.Bluetooth);
SYSTEM_PROFILER=$(system_profiler SPBluetoothDataType);
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\" \"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}\" ]] &&
OUTPUT1=\"${OUTPUT}$(awk '/BatteryPercent/{print substr($0)}'<<<\"${I}\")${!I}%\";
done;
printf \"%s\" \"${OUTPUT1}\";
fi"
set OUTPUT2 to do shell script "
OUTPUT2='';
BLUETOOTH_DEFAULTS=$(defaults read /Library/Preferences/com.apple.Bluetooth);
SYSTEM_PROFILER=$(system_profiler SPBluetoothDataType);
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\" \"BatteryPercentLeft\");
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}\" ]] &&
OUTPUT2=\"${OUTPUT}$(awk '/BatteryPercent/{print substr($0)}'<<<\"${I}\")${!I}%\";
done;
printf \"%s\" \"${OUTPUT2}\";
fi"
if OUTPUT2 is " " then
return " "
else
set BatteryLevel to word 2 of OUTPUT2 & "%" & "
" & word 2 of OUTPUT1 & "%"
end if
if BatteryLevel is "" & "
" & "" then
return " "
else
return BatteryLevel
end if
end checkBattery
--thanks to @yyuuiko for the base of the code!
--thanks to @GoldenChaos for the great problemsolving idea for Catalina!
EDIT: I understand from the other thread that you use AirPods Pro. Not sure regarding compatibility. Maybe try this code for AirPods Pro, idk if it still works though that's why I didn't publish it yet (I wrote it months ago when I could get hands on a pair of AirPods Pro for an afternoon).
return checkStatus()
on checkStatus()
--GET STORED NAME
tell application "BetterTouchTool"
--attempt to get variable
try
set LclAirPodsName to get_string_variable "AirPodsWg_DevceName"
end try
end tell
--END GET STORED NAME
--set myString to button returned of (display dialog "Connected?" buttons {"Yes", "No"})
--set myString to "name: DR-BT101 Connected: " & myString
(*uncomment line below when done testing*)
set myString to do shell script "system_profiler SPBluetoothDataType"
--initial check if it's not even there
if myString does not contain LclAirPodsName then
return " "
else
--find out if connected/disconnected
set AppleScript's text item delimiters to "name:"
set myList to the text items of myString --each item of mylist is now one of the devices
set numberOfDevices to count of myList
set counter to 1
repeat numberOfDevices times --loop through each devices checking for Connected string
if item counter of myList contains LclAirPodsName then
if item counter of myList contains "Connected: Yes" then
return checkBattery()
else if item counter of myList contains "Connected: No" then
return " "
else
display dialog "Error Parsing" --this shouldn't happen
end if
end if
set counter to counter + 1
end repeat
end if
end checkStatus
on checkBattery()
set OUTPUT1 to do shell script "
OUTPUT1='';
BLUETOOTH_DEFAULTS=$(defaults read /Library/Preferences/com.apple.Bluetooth);
SYSTEM_PROFILER=$(system_profiler SPBluetoothDataType);
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\" \"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}\" ]] &&
OUTPUT1=\"${OUTPUT}$(awk '/BatteryPercent/{print substr($0)}'<<<\"${I}\")${!I}%\";
done;
printf \"%s\" \"${OUTPUT1}\";
fi"
set OUTPUT2 to do shell script "
OUTPUT2='';
BLUETOOTH_DEFAULTS=$(defaults read /Library/Preferences/com.apple.Bluetooth);
SYSTEM_PROFILER=$(system_profiler SPBluetoothDataType);
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\" \"BatteryPercentLeft\");
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}\" ]] &&
OUTPUT2=\"${OUTPUT}$(awk '/BatteryPercent/{print substr($0)}'<<<\"${I}\")${!I}%\";
done;
printf \"%s\" \"${OUTPUT2}\";
fi"
set BatteryLevel to OUTPUT2 & "
" & OUTPUT1
if BatteryLevel is "" & "
" & "" then
return " "
else
if OUTPUT2 is " " then
return " "
else
return OUTPUT2 & "
" & OUTPUT1
end if
end if
end checkBattery
--thanks to @yyuuiko for the base of the code!
--thanks to @GoldenChaos for the great problemsolving idea for Catalina!
you are the man - the second script fixed it :-)) I get the icon and after changing the wording in the script I got it all as it should - yeah
One question remains - I don't see the icon on app specific touchbar settings - any way to accomplish that? Is there copy paste or something like that? (:-)) found that too
The latest preset (the one created by me) supports both airpods and pro, it can detect the model and change the icon to the corresponding image, if you dont mind, try it out
@Noon_Chen any idea where apple hide the original icon used feg in iOS?
I like unified design and would love to make that little "adjustment" to your awesome widget since I use both, AirPods 1st Gen and AirPods Pro, but I'd love to use this icon too. Adding it in the script is no problem, but finding a usable icon is
Sorry for the delayed response, you can find macOS default Bluetooth device icons in the following location: /System/Library/Frameworks/IOBluetoothUI.framework/Versions/A/Resources
Thank to you as well! As I looking thru the plists in that folder, I think I could create a widget that can support all bluetooth headphones from apple, and change the icon accordingly.
This would be nice indeed.
RN I struggle with the fact that I use several W1/H1 headphones (AirPods 1st Gen, AirPods Pro, Beats). I’d like to use something like “short tap”VS“long tap” to connect one device or another but the widget itself a checks only for one device at this time. Have to check for it later.
I could help out with as I said AirPods 1st Gen, AirPods Pro and Beats Solo
I found some hack/workaround to check for the battery by looking all the time for every device - but that appears like shooting a fly with a cannon bullet
Great! Can you run defaults read /Library/Preferences/com.apple.Bluetooth in the terminal and use ⌘+F to search the name of your Beats Solo, what is the key of the battery info?
This is the battery key of my beatsX, I want to make sure is it the same for all non-airpods model.
Thanks! It's actually good news, there could be only two sets of battery key, one for airpods and one for others, I think the preset would be ready today, I'll inform you when it's done.