HELP: Better AirPods connection Widget: Development


#1

Continuing the discussion from A better AirPod Connection Widget: less space for the same information:

Show Context

@GoldenChaos, @Caliguvara, I don't have AirPods so I'd like you to test my modifications


Change List:

  • General Aesthetic Refinements: More Pixel-Precise icons and better spacing
  • Auto Setup
  • Better Error Feedback

Notes:


HELP / TEST / IMPROVE:

  1. :white_check_mark:[d1.1] Help: The setup window does not connect to the AirPods when you press OK, it just sets the variable. You'd need to tap the widget again to connect which may feel counterintuitive to the user.
    I don't want to repeat the connect code after the variable setting, so I'm guessing functions such as onCheck and onConnect are the way to go, but I'm unfamilliar with applescript functions so I need some help here.
    TLDR: Activate the connect functions after the setup functions. Minimise repeated code.
    (Task Complete: The widget now attempts to connect after setup.)

  2. Test: Test if it works. If it does but it's clunky, help with optimisation and smoothing it out.
    - Test as a normal user would use it
    - Test a blank name
    - Test the connection
    - Test an incorrect name

  3. Improve: I'm not sure about my wording for the windows, so if you could word it better and make it more understandable that would be great. I'm having trouble describing "the setting of the variable"

  4. :white_check_mark:[d1.1] Improve: The icon isn’t pixel perfect so it’s a bit blurry on the edges, especially the earpod holes and it’s edges. I will properly align and perfect this sometime to achieve a more CRIISPY, more legible icon. This is important as this icon has lots of small details that need to be read!
    (Task Complete: Icon refined with sub-pixel alignment)

  5. Discuss: You can hold the widget to set the name again (in case you changed the name of your airpods) How do you think we could let the users know you can do this?

  6. Discuss: Get back to me on this post with your findings, suggestions and any changes. We'll version them based on a "d1.1" system where the d stands for development.
    Please add the version number in BTT before you export and upload!

  7. Stretch Goal: Indicate Charging Airpods
    The idea for me is that there would be multiple icons for all combinations. When charging, the L or/and R symbol and the appropriate airpod in the icon would turn green, and a lightning icon would display under the corresponding airpod. Mockup Below:
    airp%20charge%20Left

Any questions, need to clarify or unsure about these tasks then just comment on the thread.


RESOURCE / VERSION BANK:

Warning! Developer use only, not for everyday use. This presets are untamed!

Compact AirPods Widget - d1.0.bttpreset (71.4 KB - yuuiko)

Compact AirPods Widget - d1.1.bttpreset (74.9 KB - yuuiko)


A better AirPod Connection Widget: less space for the same information
#2

I found a little hiccup on my side:

If you press a cancel button on any popup window it’ll think an error occured and show you the error popup window. I’m not sure how to fix this, mainly I don’t know how to assign a task to the cancel button.

Just thought I’d let anyone contributing know, this is probably all I can properly test as I don’t have AirPods.


GoldenChaos-BTT Support and Feedback Thread
#3

Development Build 1.1

Hi again, I've just added some improvements and bugfixes. I think this one is pretty ready to head out, but @GoldenChaos and @Caliguvara please verify that it works well.


SUB-PIXEL Perfect Icons!
The icons and aesthetic were touched up and are now final, unless you want to make changes.
It is now sub-pixel perfect, aligned down to each R-G-B subpixel! It's crazy sharp and crispy, looks amazing.


(you'd need to see for yourself!)


Scripts made more Robust
Tested and error handling has improved. I've figured out how to react to the window buttons so now pressing the buttons on the popup are optimised and actually work properly. The widget now also tries to automatically connect as soon as you press the 'done' for the setup.


Window Rephrasing?
I think I rephrased some windows, but I didn't keep track of this very much. Please feedback on how I should explain the stuff better...

General clean up was done too, but;

excuse my temporary controls in there, which are inactive. They are just there to let me control things while i worked on the isolated preset.

Download d1.1 at the top post. Hope it can make it to v1!


A better AirPod Connection Widget: less space for the same information
#4

Sweet, I'll check this out as soon as I've got my settings window stuff working :grimacing:


#5

Ok, just installed it.
You're right, your icons are beautiful! :open_mouth:
Unfortunately, I don't get the widget to do what it should. Popup, I enter the AirPods name, Beep, BTT Windows greys out and goes to background, the Bluetooth Menu enrols, and BTT jumps in the Dock. After a few seconds I get the Popup that AirPods Widget could not find my AirPods.

Once I connect them manually the Return Battery works perfectly, the problem must be somewhere in the predefined action. I'm gonna take a deeper look into it when I have the time and will totally come back to you!


#6

Any updates @Caliguvara?


#7

Not yet, last exam on Thursday! :wink: I'll be able to dive into it next week! Sorry :frowning:


#8

I ran into the same issue as @Caliguvara.


#9

@arete, Unfortunatley I can't check what's wrong with that as I don't have AirPods myself. :wink:

@Caliguvara, I think it might be an issue with the variables being inserted into the script, I'll scann for errors but I can't test if the result works.


#10

@Caliguvara

Try this code for the action script, There is now a Request for the variable within the connect function.

I thought maybe local (within the script) variables didn't carry over into functions, but I can't test this.


--1: GET STORED NAME / ASK TO SET NAME IF NOT PRESENT
tell application "BetterTouchTool"
	--attempt to get variable
	try
		set LclAirPodsName to get_string_variable "AirPodsWg_DevceName"
	end try
	
	--if AirPodsWg_DevceName has not been set
	if LclAirPodsName is missing value or LclAirPodsName is "" then
		
		-- first time insert name window
		set theResponse to display dialog "Please provide the name of the AirPods that you wish to connect." with title "AirPods Widget" default answer "Johnny's AirPods" with icon note buttons {"Cancel", "Connect"} default button "Connect" cancel button "Cancel"
		
		--if "connect" button is pressed of the setup window
		if the button returned of the result is "Connect" then
			
			try
				--store BTT variable
				set_persistent_string_variable "AirPodsWg_DevceName" to (text returned of theResponse)
				
				--connect AirPods
				return my connectAirPods()
				
			on error
				--error alert window 
				display dialog "There was an error while setting up the AirPods widget. 

Try again to connect your AirPods, or contact the developers \"GoldenChaos\", \"Caliguvara\" or \"yyuuiko\" at the BTT forums if the issue persists." with title "AirPods Widget" with icon note buttons {"OK"} default button "OK"
				
				if the button returned of the result is "OK" then
					return
				end if
			end try
			
		else --if window pressed cancel
			if the button returned of the result is "Cancel" then
				return
			end if
		end if
		
		-- 2: CONNECT AIRPODS BASED ON STORED VARIABLE
	else --if variable is found
		return my connectAirPods()
	end if
end tell

on connectAirPods() --Connect AirPods Function
	tell application "BetterTouchTool"
		--attempt to get AirPods variable
		try
			set LclAirPodsName to get_string_variable "AirPodsWg_DevceName"
		end try
	end tell
	
	activate application "SystemUIServer"
	tell application "System Events"
		tell process "SystemUIServer"
			-- Working CONNECT Script.  Goes through the following:
			-- Clicks on Bluetooth Menu (OSX Top Menu Bar)
			--    => Clicks on device based on variable name
			--      => Clicks on Connect Item
			set btMenu to (menu bar item 1 of menu bar 1 whose description contains "bluetooth")
			try
				tell btMenu
					click
					tell (menu item LclAirPodsName of menu 1)
						click
						if exists menu item "Connect" of menu 1 then
							click menu item "Connect" of menu 1
							return "Connecting..."
						else
							click menu item "Disconnect" of menu 1
						end if
					end tell
				end tell
				
			on error
				--error "connection" alert window 
				tell application "BetterTouchTool" to display dialog "AirPods Widget could not find your AirPods! 

- Make sure they are paired, then try again
- Setup the AirPods widget again, maybe you spelt your device wrong..." with title "AirPods Widget" with icon note buttons {"Reset Widget", "OK"} default button "OK"
				
				if the button returned of the result is "Reset Widget" then
					tell application "BetterTouchTool" to trigger_named "Reset AirPods Widget"
				else --if window pressed OK
					return
				end if
			end try
		end tell
	end tell
end connectAirPods

-- code templates and previous code found in non-functionised version due to massive lag.

#11

Hey @yyuuiko :slight_smile:

Unfortunately, your current script creates a loop and don't stop asking for the name of the AirPods which should be connected (it does not matter of they are connected already or not), BTT is not usable anymore at all. The "Reset widget" button does not work.

Cheers


#12

Hi @Irthen,

This preset is not complete, so strongly do not recommend using it for your everyday preset!

Thanks for your feedback though, but unfortunatley I can't test this issue as i don't have AirPods myself.


#13

Hi @yyuuiko

you're welcome :slight_smile: yeah, I know, just had to get some files back out of my backup, everything is okay.