Using AppleScript: which type?

Hey, I got a tip to help me pressing a button of an open window in my LogicPro DAW.

tell application "System Events"
tell process "Logic Pro X"
click button 3 of window 1
end tell
end tell

This presses the "bypass" button. In BTT, there are two AppleScripts. How are they different?

Note: In my first version of this post, my script wasn't working because the "X" in LogicPro was missing. The script works fine. Answer by Andreas is still relevant. :slight_smile:

Hi @JohannesSchv ,

If I understand you correctly, you're asking about the difference between these two BTT Actions:

  1. Run Apple Script (blocking)
  2. Run Apple Script (async in background)

Is that right?

Basically: "run apple script (blocking)" always works, however it blocks other things from executing and cause small delays. "Run Apple Script (async in background)" works for most things but might not work when showing UI is required.

Your issue sounds more like something is wrong with the Apple Script.

1 Like

following up on this Andreas, i have 2 questions that I was hoping you could help out with relating to script as I've become pretty reliant on them

  1. is there a way to only move on to the next step in the sequence when the script is finished? "async" runs but then everything in the sequence keeps going whereas "blocking" blocks all of BTT, I can't find an in-between

  2. is there a way to only move on in the sequence if the script yields a specific result? this is especially killing me (not even ChatGPT can help) but I see that theres a "Result" section under the script however I cant figure out for the life of me how to get BTT to react depedning on the output. I've read thru the docs a couple times and can't find much help on this. I've also tried utilizing the "If Java script return True" but the docs also don't have much guidance on this.

My workaround (which is pretty complicated) is to have the applescript save "True" to a string variable then have a "if condition" that detects if its true. THEN I use the set varibale function to reset this variable to "0" as it is used by multiple sequences but its become a real pain. Appreciate any help or guidance on this and again, you are literally a god send for this app! I've wasted way too much time not studying and playing around with BTT :sweat_smile:

this is the default, you can test it like this, the hud will only show after the apple script is finished (in this example the apple script just delays 5 seconds)

this is currently not supported with pure apple script, but can easily be done with apple script wrapped in java script. Here is an example using the "If Java Script Returns True" action:

async function someJavaScriptFunction() {
    let result = await runAppleScript(
        `
	set theResponse to display dialog "What's your name?" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue"
(text returned of theResponse)
	`
    );

    if (result.includes("hello")) {
        return true;
    } else {
        return false;
    }

}

Ok I see it was happening so fast the I didn't realize it was waiting but now when I add the delay it works. Also THANK you for the template going to save this for the future!!

Why is the script working if I press the Start Scrip Button in BTT, but it is not working, if I assign a shortcut to it (tried different types)?

That I don't know, there should be no real difference. Maybe the script depends on the active window?

Apologize. It works. I had the main group/ folder, where the action is based in, deactivated, I oversaw that small eye icon.