Show/hide fails if applied to multiple apps in same shortcut.

Bug Description:
I've created a keyboard shortcut (trigger) to show/hide two applications at once. There are simply two actions in the shortcut: Show/hide one app, then show/hide the other app.

When the trigger is activated, it will randomly work, or it'll show or hide one app but not the other, or it'll do nothing.

If an individual shortcut is made for each app with the only action being to show/hide that app, it works fine. Combining the two in one trigger results in the incorrect behavior above.

Affected input device: MacBook Pro

Screenshot:
Screen Shot 2021-10-17 at 1.59.09 PM

Device information:

  • Type of Mac: MacBook Pro 2020 and MacBook Pro 2019 (reproduced on both)
  • macOS version: Big Sur 11.6 and Big Sur 11.4 (reproduced on both)
  • BetterTouchTool version: 3.579 (1722)

Additional information - testing and workarounds:

Successful Workaround - 2 Separate Shortcuts for Each App: In my example, I'm doing this to make both the Messages and Slack applications appear or be hidden with a single keyboard shortcut. That way I can quickly bring them up and hide them again instantly. Since I haven't been able to get a trigger to work with both actions in the same trigger, I've made two separate shortcuts, one for each application, which each has only one action which is to show or hide that one app. Screen Shot 2021-10-17 at 2.06.33 PM

Failed Workaround - One action that calls above 2 shortcuts: I tried a workaround of creating a trigger that would call the above two individual shortcuts, but that didn't help and resulted in the same behavior.

Failed Workaround - Adding a Delay: I've tried adding a delay between the show/hide actions, but that doesn't help.

Bring to Front Helps but Doesn't Solve: I've tried adding an action to bring the the Messages app to the front before the show/hide commands. This seems to make it a little more consistent, but not much.
Screen Shot 2021-10-17 at 2.08.33 PM

I've run out of things to try. This seems like a clear bug. Appreciate any help :slight_smile:

weird, I’ll have a look!

1 Like

Thanks @Andreas_Hegenberg!

Off-topic comment - you're a GOD DAMN HERO for making BTT! Like legions of your users, I utterly depend on your app.

2259e7_b35de930f6064e62804db0bc03c6e175~mv2

Thank you!

So the problem is a bit complicated. For simplicity reasons (and because I use the action like this), BTT only hides a window if it is active when using this action. For windows which are not focused/active, BTT assumes they are hidden. Because on macOS only one window can be active, this causes the conflict here.

In alpha 3.586 (will be available in a few minutes), I'm making this behavior explicit. You can try to UNcheck this option:

Hi @Andreas_Hegenberg - thank you for such a quick response! I installed the alpha. This helps but doesn't solve the issue completely. Can you make it show/hide regardless of whether the window's in focus or not? So in my example, regardless of focus state, the shortcut will simply always hide both Slack and Messages or make them shown.

Right now in the new alpha it's working like this, with "Only treat active window as visible" unchecked:

  1. Start with Slack and Messages both hidden.
  2. Shortcut toggles both to shown state.
  3. Click on another window other than these two, so neither is in focus.
  4. Shortcut toggles both to hidden state.
  5. repeat and it flips them both to shown / hidden / shown / hidden as intended. But you need step 3 where you make sure neither window is in focus before triggering the shortcut again.

If at step 3, one of the two windows is in focus, then it starts to fail and hide one but not the other. What it specifically does isn't consistent.

Use case: You bring both the messaging apps into focus, type a message in one of them, then want to quickly hide them both again. You've just typed a message in one of them, so it's in focus.

I think if you just make it ignore the focus state and toggle show/hide regardless, it'll work.

Are you sure you un-checked the checkbox for both actions?

Yes - these are the exact settings:


@Andreas_Hegenberg Here's a video of the behavior. I'm hitting the shortcut repeatedly so you can see what's happening. The two windows should disappear or reappear in tandem, but almost immediately one will fail to hide or show and then they're randomly out of sync or in sync. I also show the settings for that shortcut and the version of BTT I'm on in the video.

https://www.dropbox.com/s/20jm8l4ev6n3ntz/BTT%20Show-Hide%20Shortcut%20Behavior.mov?dl=0

Sorry this is more complicated than it looks like. I'll do another try tomorrow.

I thin 3.594 might work better. (Currently uploading)

Hi @Andreas_Hegenberg - Thank you for continuing to give this a shot! I'm on 3.600 right now, and it does work better, but still somewhat unpredictable behavior. I think it has to do with whether a window is in focus or not.

Now most of both windows are either shown or hidden at the same time. Sometimes one window will show/hide and not the other. The more common thing is that when I trigger the shortcut, about 40% of the time the windows don't show or hide at all (though I can see focus shifting with them).

Would you like me to send a video?

This is with "only treat active window as visible" UN-checked. If I check it, then it's very inconsistent like before where three behaviors are equally likely: nothing happens, one window show/hides, or both do.

I have reverted this for now in 3.604 as it will not work correctly using the current approach.

I need to create a separate action which is specifically made for showing/hiding multiple apps. That way it can check whether any of the chosen apps has a visible window, and hide the apps in that case - if not show them.

For now this script should also work better (run it using the "Run Real JavaScript" action). You'd need to enter the file urls to the apps you want to show/hide in the APPS_TO_SHOW_OR_HIDE array.

async function cycleHiddenAndVisible() {
  const APPS_TO_SHOW_OR_HIDE = [
    "file:///Applications/Sublime%20Text.app/",
    "file:///Applications/Visual%20Studio%20Code.app/",
  ];

  let showHideAction = {
    BTTPredefinedActionType: 177,
  };

  let variableName = "visibleOrHidden";
  let variable = await callBTT("get_string_variable", {
    variable_name: variableName,
  });

  if (variable === undefined) {
    await callBTT("set_string_variable", {
      variable_name: variableName,
      to: "visible",
    });
    variable = "visible";
  }

  if (variable == "visible") {
    for (let app of APPS_TO_SHOW_OR_HIDE) {
        showHideAction.BTTAppToShowOrHide = app;
        showHideAction.BTTShowHideAppConfig = '{"BTTShowHideSpecificAppOnlyHide":true}';
      callBTT("trigger_action", {
        json: JSON.stringify(showHideAction),
      });
    }

    await callBTT("set_string_variable", {
      variable_name: variableName,
      to: "hidden",
    });
  } else if (variable == "hidden") {
    for (let app of APPS_TO_SHOW_OR_HIDE) {
        showHideAction.BTTAppToShowOrHide = app;
        showHideAction.BTTShowHideAppConfig = '{"BTTShowHideSpecificAppOnlyShow":true}';
        callBTT("trigger_action", {
          json: JSON.stringify(showHideAction),
        });
      }

    await callBTT("set_string_variable", {
      variable_name: variableName,
      to: "visible",
    });
  }

  // return to BTT
  returnToBTT(variable);
}

cycleHiddenAndVisible();