Launch Application, or cycle windows if active

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

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:

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)

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:

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!

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

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

It just occured to me it should be possible for your flow to first push the arguments on somewhere (environment variable, BTT variable, or a static temporary outfile) and then your script can itself pop the arguments from there and go have fun with them.

I'm having incredible issues with btt lately and can't find out whats causing it. Incredible lag on keyboard and mouse input, quitting btt immediately alleviates the problem, but only after a few seconds they reappear. Investigating.

Possibly using experimental dropbox / icloud sync? (That has been causing performance issues for some users lately)

I'm looking into something similar.
I see the functionality in Save/restore specific window layout generates and stores this:

[{"size":"{654, 551}","windowName":"ToothFairy","parentTitle":"ToothFairy","position":"{378, 752}","role":"AXWindow"},{"size":"{654, 551}","windowName":"ToothFairy","parentTitle":"ToothFairy","position":"{378, 752}","role":"AXWindow"},{"size":"{799, 448}","windowName":"Open","parentTitle":"Smart JSON Editor","position":"{1040, 311}","role":"AXWindow"},{"size":"{2446, 1547}","windowName":"Launch Application, or cycle windows if 

I'm looking for a way for my shell scripts to always have access to the following information:

  • applications with visible windows and the position of those windows
  • the title of all visible windows, so I can parse which document is open in that window

But I can't find a way for btt to generate this information without user interaction.

Preferably a lot of what BTT offers of ffunctionality I'd really prefer to access either via command line parameters to btt directly, or preferable by sending BTT a JSON or similar, tips on this would be awesome.

Yes, I'm using the dropbox sync as I work on two machines.
Perhaps I should disable it and just script quitting btt, pulling latest btt config from my dotfile repo, then restarting btt.

You can trigger most of BTT's functionality using Apple Script or using the built in webserver (if enabled), but I'm not sure whether it would help in this case.

http://docs.bettertouchtool.net/docs/1102_apple_script.html

command line parameters would be awesome and enable a lot of better automations, enable flow control and logic not currently directly possible within btt.

What is the best way to export two presets, combine them into one, and reimport those to btt? If my settings are corrupt this would be good, yes?