Launch Application, or cycle windows if active


#1

I'm looking for the ability to Launch an application, or, if it's currently active, cycle the windows.

I'm able to recreate it with AppleScript, but that adds a ~200ms delay, which is pretty noticeable, would be cool if there was a faster way included with BTT.

Here's my script if anyone is interested: https://gist.github.com/mikew/d75c2dbb636dd5ba81d6be960540f905

You'll need to run it with oscascript, since that's apparently the only way to pass arguments to AppleScript. I'm using "Execute Terminal command", but "Execute Shell task" should also work.

/usr/bin/osascript /Users/mike/Desktop/launch-or-cycle-windows.applescript com.google.Chrome

#2

I think you could just execute both actions all the time. The Launch application action in BTT should only activate the app if it's not launched and not interfere with the shortcut:


#3

Not sure if I've set the actions up correctly, but with this setup, it's switching to the app and immediately switching windows, where I'm looking for switch to the app if it's not focused, and if it is, then cycle windows.

(this is using the touchbar, not sure if you can configure things differently in another area)


#4

Ah ok, then this might not work. Sorry!

I think your Apple Script could be faster if you'd make it static (i.e. without arguments) and use the dedicated Apple Script action in BTT. This is because when using osascript, it needs to recompile the script on every use, when using BTT it will cache the compiled scripts, also the BTT script runner processes are already loaded which will save a few more ms. I think I should add support for passing parameters :slight_smile:


#5

Cool, I was wondering what the difference was with BTT's own Apple Script. I was surprised that even when using Script Editor to build a .app it was still slow. I don't mind copying the script between multiple for now. Let's see!


#6

Yeah for some scripts it doesn't help, but it's definitely worth a try.


#7

It's definitely faster now, thanks for the tip.