Floating menu script not always updating and getting stuck. Not sure if bug, or else is there a way to force an update?
I have a floating menu behind the Notch that uses Applescripts to launch and play Spotify if it is not already running, and if it is already running, to press play if it is paused, or pause if it is currently playing. There is also a Menu Item that gets the current artist and track name from Spotify and returns it. This menu item runs every 1.25 seconds (I changed it from 1 to 1.25 as part of my debugging).
My bug is that the Menu Item showing the track does not always update, and can get stuck on either a previous track, or returning the other outputs, such as "Spotify is Paused". I can't find a way of fixing it when it gets stuck except for restarting BTT. I don't know what causes it to get stuck, it just happens seemingly randomly. Happy to upload the preset if it helps. Thanks.
Uploading the preset is a good idea. (or send to andreas@folivora.ai)
A general tip: potentially wrap your script in try catch blocks, to catch any errors that might happen
try
#your script
on error errStr number errorNumber
# something in case of error
end try
No problem! Look forward to hearing back from you later.
As a quick off-topic aside (but adjacent to this preset), when using an icon from the disk for a menu item, does it get stored internally to BTT and so I can remove it from its location after choosing it as an icon, or does BTT always look up the original location of the icon?
Ah but I'm using the Icon section further down, not the Image in the Background section, as I want the Menu Item to look like a button and change colour when I hover over it. If I use the Icon as the background, then it doesn't highlight when I hover over it.
Oh, weird. I'd say pretty consistently after an hour or so of use. When you tested it were you actively using it to pause/play Spotify and checking it had updated after tracks move on?
Could you try closing and quitting Spotify and restarting it few times to see if that's what causes it. It's been difficult for me to pin-down an exact cause - mostly I just notice it gets stuck after a while.
But just now it's stuck again, and the only thing I can say with confidence is that earlier it was working, I have since quit Spotify, and now when restarting it it's stuck again, so perhaps it has something to do with that?
Also, just to be clear, it's only the returned text of the Menu Item showing the currently playing artist and track name that is getting stuck. The function of the actions that are triggered by clicking on the all menu items continue to work as scripted.
Hi Andreas. Thanks for the debugging. Downloaded the 4.588 alpha. Initially thought it seemed better at keeping and staying updated, but it's just gotten stuck again. I'm struggling to figure how to reproduce it consistently. It feels pretty random to me.
Strange, I have it running successfuly since 2 hours so far Will debug again once it gets stuck again (the script itself seems to run fine, it's updating the text that gets stuck)
I know why it's happening but haven't figured out what leads to this situation. It's basically "just" a rendering problem, the script is running fine. Will continue to investigate tomorrow.
I'm running a similar preset and have done a ton of debugging so this may be helpful. (My preset only shows the artwork, title and song in the notch but as a floating menu). I'm not a developer but will try my best.
Essentially mine always gets in the paused state (no art/title/artist) when BTTInitialize() is called. The workaround I have is I re-enable the Notch Bar (Toggle BTT Notch Bar Visible/Hidden).
This allows these User Script temporary variables to appear and be available (confirmed via a comparison within BTT Settings):
BTTCurrentlyPlaying
BTTNowPlayingInfoArtist
BTTNowPlayingInfoTitle
BTTNowPlayingInfoAlbum
For some reason, they are not available if the notch is disabled but they are available if the notch bar is enabled.
Script I am using:
if(data.note == 'BTTNowPlayingInfoChanged') {
let currentlyPlayingSong = await get_string_variable({variable_name: 'BTTNowPlayingInfoTitle'});
let currentlyPlayingArtist = await get_string_variable({variable_name: 'BTTNowPlayingInfoArtist'});
let currentlyPlayingStatus = await get_string_variable({variable_name: 'BTTCurrentlyPlaying'});
...