GoldenChaos-BTT Support and Feedback Thread

Audio AirPlay devices

This is super easyCheck out the C3 version of my preset, you'll find an "AirPlay" (Audio only) group there.

The group opens through a button that displays the current output device, and if this is an AirPods Device displays the battery status in the line below.

The Script to find the connected device (used by myself to open the group)
--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 returnValue to {}

tell application "iTunes"

set AirPlayName to name of the first AirPlay device whose selected is true

if AirPlayName contains LclAirPodsName then

set returnValue to (AirPlayName & (checkBattery() of me)) as string

else if AirPlayName contains "Computer" then

set returnValue to (AirPlayName & (checkStatus() of me)) as string

else

set returnValue to AirPlayName

end if

return returnValue

end tell

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"

return & "

" & "Ⓛ" & OUTPUT2 & " Ⓡ" & OUTPUT1

end checkBattery

--Code by @Caliguvara and @Zikade from MacTechNews.de
Script to display an AirPlay Device (needs to be repeated *n* times, returns the names of the devices)
tell application "iTunes"
set listOfAirPlayNames to (get name of every AirPlay device)
set AirPlayDevice to the first item of listOfAirPlayNames
return AirPlayDevice
end tell
--code by @Caliguvara

You have to change the third line to second item, third item,… n times.

Only bugger for now, I return a variable, not a string, so the Widget won't be able to tell you if several AirPlay Devices are connected. More information in this MacTechNews.de discussion.

Script to connect to a desired AirPlay Device
tell application "iTunes"
set listOfAirPlayNames to (get name of every AirPlay device)
set chosenAirPlayName to the second item of listOfAirPlayNames
set current AirPlay devices to AirPlay device chosenAirPlayName
end tell
--code by @Caliguvara

Of course you have to change the third line to second item, third item in order to adjust them to their respective widget.

Take a look into it! Would be happy to hear your opinion about it :slightly_smiling_face:


Mail

Another question halfway OT - do you know a mail program that works with apple script? My idea is to use the email notifications of Folivora to display notifications from the community in the Touch Bar without spamming my main mail app…