Floating menu script not always updating and getting stuck. Restarting BTT fixes.

I think I found the issue where the floating menu is not updating - if I use "External file" for the script it is NOT working, however if it is "Inline Text" and the same script (applescript) is pasted it is working, I've also tested this with the simple script in that post - Floating menu script not always updating and getting stuck. Restarting BTT fixes. - #36 by Andreas_Hegenberg

Thanks, I'll check!

I think it is not related to the external file location. However I might have found the issue. Hope it is fixed in 4.879 (uploading now)!

Hey @Andreas_Hegenberg , I think after that update a some of the BTT/default variables are missing. At the moment I'm comparing the variables on version 4.879, with 4.878 (or maybe a little older), but I for example I cannot see:

  • CurrentKeyboardInputSource
  • All BTTNowPlaying*, except BTTCurrentlyPlayingApp == app_mode_loader, BTTCurrentlyPlaying == 1
  • BTTLastTerminalCommandResult (in the older version it was empty, but it was showing)

I'm not sure if these are all the missing ones.

What exactly do you mean by missing? Did you try querying them? (most of them only become available when used)

Specifically for BTTNowPlaying* I'm querying them, but they does not appear in the list of variables. When I run the script which is querying them it is showing "missing value". Here's my script which is using the BTTNowPlaying* vars, which was working before the update.

on itemScript(itemUUID)
	tell application "BetterTouchTool"
		get_number_variable "BTTCurrentlyPlaying"
	end tell
	tell application "BetterTouchTool"
		set playing_not_playing to get_number_variable "BTTCurrentlyPlaying"
		-- Change PlayPause based on the value of playing_not_playing
		if playing_not_playing is 1 then
			set PlayPause to "Playing"
		else if playing_not_playing is 0 then
			set PlayPause to "Pause"
		else
			set PlayPause to "Unknown" -- Optional: handle unexpected values
		end if
		set songTitle to get_string_variable "BTTNowPlayingInfoTitle"
		set songArtist to get_string_variable "BTTNowPlayingInfoArtist"
	end tell
	set combinedInfo to PlayPause & " | " & songArtist & " | " & songTitle
	-- set combinedInfo to songArtist & " | " & songTitle
	return combinedInfo
end itemScript```

weird, I didn't change anything about these recently. I just tried your script here:

Does your script work if you run it outside of BTT in script editor? (maybe your script is not started in BTT for some reason)

You have three backticks at the end of your script, but these were probably just added when you pasted it in the forum here, right?

This is quite strange,
If I open the script in the Script Editor and remove first and last lines, click on Compile it is giving warning "The document could not be autosaved. (Error-1 752)", but if I copy/paste it to a new script it is working as expected. So once I did this, BTT floating menu started working, so I'm curious if this somehow queried the needed variables which were then picked-up by BTT (or this is not how this works?). I've restarted BTT few times before reporting, but without success, also like mentioned when I ran the script manually (via the "Run Script" button), "missing value" was showing for 2 of the variables.

However I think the issue with the "External File" is not resolved :\ - it behaves the same way like described here

I think it was this:

should be resolved now!

2 Likes

Yep, this is now working. Thank you!

Hey @Andreas_Hegenberg,

Issue 1:
I've setup a Submenu item with a script, however the submenu is not updated when the script runs: every 4sec, run on first load and "Always Run When Menu Item Becomes Visible" are enabled. I have a "Standard item" with the same configuration (same script, same config for the script etc.) and it is updating every single time.

In order to force the update of the submenu I can enable "Run Script On Menu Hover" and then it starts working even without hovering the specific submenu, just any of the items on that floating menu.

Issue 2:
With the recent updates also another "Standard Item" with a javascript stopped updating (again the same config like above - every 4sec etc.). It should show a custom var, which is avaialble (checked from BTT Settings/Scripting BTT), but it is not shown until I hit "Run Script"

BTT version: 4.926 (2024120301)

Is it a item in a submenu or the actual submenu item that opens the submenu?

The actual submenu, I have not added any items in the submenu yet.

ps: I've added another issue (again not updating item) in the previous post

I just tried to reproduce but it seems to work fine here, could you copy & paste the non-working item here, maybe some specific setting is causing it.

//edit: ah I think I see the issue after restarting it doesn't launch the refresh timer in some situations. I'll have a look

4.930 alpha (uploading, should be available in 5 min) should fix the issue with submenu items, however I can't seem to reproduce the issue related to standard items. Would be great if you could check whether it still happens in 4.930

This is for issue 1:
btt_submenu_non_working.bttpreset (3.9 KB)

It seems that I can force to update it also if I toggle the item size between "Fit Content" and "Define Min and Max Width and Height in Pixels". After this it starts updating without issue until a BTT restart.

@Andreas_Hegenberg, I can confirm that 4.930 alpha fixes the issue with the non-updating submenu (issue 1). Thank you for the quick fix as always!

However issue 2 is not fixed. Here's the menu config for it:

exported_status_message_not_updating.bttpreset (4.5 KB)

I can force update it doing the same thing I've explained above - toggle item size OR click on "Run Script" manually.

could you share the youtube javascript that is referenced in this?

Here it is:

async function itemScript(itemUUID) {

    let status_message = await get_string_variable({variableName: "custom_var_video_id"});

 //    await set_persistent_string_variable({variableName: "custom_var_status_message", to: video_id})
	// console.log('video_id', video_id);
	return status_message;
}

And here's a screenshot of the var that it is set, but the menu item (last one, with text- "some text") is not updated:

is this variable maybe also set as a temporary variable but not updated?
In that case the temporary one would be returned.