I'm trying to configure BTT as a Workspace Manager (opens files/apps and rearranges windows across displays). This requires a lot of IF statements to identify whether a specific app/window is already open, switching to it if so, waiting for the switch to happen successfully, etc.
I already have a few of these where the conditions are hardcoded into each step and are a pain to reconfigure whenever I want to add another app. What I am looking to do is to set all the required variables in the first few steps so that I don't need to go into each condition and reconfigure everything.
TL:DR - Is it possible to set a condition that compares two variables, one of them being a custom variable?
Apologies, but I can't seem to get it working, even for a test! I copied your code and just changed the variables. Clicking on run does not display a result, and neither does triggering (doesn't continue past IF). As you can see, the variables are in fact set to the same value. Puzzled!
Also, I realize i wrote a poor TL:DR for my post. In order to get this to work I would need to access the current app name to compare it using this JS method. Is it possible to access a "BTTActiveAppName" variable (or something)? BTT has an AppName variable in CAGs and Advanced Conditions - is there anyway to script either?
Even better of course would be to be able to use custom variables to compare to a variable in Advanced Conditions like I'd previously suggested, but I guess that may not be technically feasible?
Your setup looks good, make sure to enter the correct function name as mentioned by @telephanth.
You can get any variable listed in CAGs or advanced trigger conditions via BTT's scripting (either get_string_variable or get_number_variable)
let variable1 = await get_string_variable("BTTActiveAppName");
Unfortunately with the default condition editor it is not possible to compare two variables, this is a technical limitation of using the system provided "predicate editor". Maybe at some point in the future I will switch to a custom implementation.
Thanks gents, got it to work. Indeed, I hadn't used the JS trigger before (nor much of JS really) so I didn't realize I had to change "Async function to call".
Unfortunately it is performing really poorly - which I find surprising for such a basic script. Maybe there's some other issue going on here? It is taking a whopping 6 seconds for the HUD to appear:
ah that should bascally be instant, maybe the variable you are using runs some apple script and maybe there is an issue with that. I might not have tested this in the if condition
I am using focused_window_app_name from ATC. I also tried appName from CAG; same results.
async function compareXY() {
let variable1 = await get_string_variable("focused_window_app_name");
let variable2 = await get_string_variable("AppNameTarget");
// Return true if both are equal
return variable1 === variable2;
}