Shortcuts only when launchbar input is active (not when application is active)

Hello. I'd like to make a simple keystroke substitution active ONLY when the LaunchBar input window is active. When you activate LaunchBar, the application doesn't become the foreground application, so making a group "Available in these applications: LaunchBar" does not work. Is there a clever way for KM to test if the LaunchBar input window is active? I just want to make the semicolon key act as the right arrow when the LB input line is active.
thanks!

It might be possible to use AppleScript to determine whether or not the LaunchBar search bar is present on the screen (and one assume's that, if it's present, it must therefore also be currently in focus or "active").

However, the obstacle I foresee in achieving what you want is that by implementing a macro that is triggered with semicolon as the hotkey, this will be triggered systemwide. Obviously, the hypothetical AppleScript can be used to determine whether or not to make the substitution, so that it is only made in the LaunchBar search bar; but the issue I'm trying to highlight it that it either nullifies the semicolon key in every other instance, or you have to tell the macro to insert a semicolon symbol in those other instances.

That seems potentially like a lot of overhead and instantiation of a macro for potentially very little gain.

Can you think of another means of doing what you want ?

Is there, perhaps, a setting in LaunchBar (as there is in Alfred) that allows it to register itself as the frontmost application upon activating the search bar ?

1 Like

It is indeed possible for KM to test if the LaunchBar input window is active or not and have the semicolon key behave how you want:

image

As @CJK says, I wouldn't recommend this method, as it slows down the semicolon key by a noticeable fraction of a second whenever you want to type a semicolon normally, but if you almost never type semicolons and have a strong reason for wanting to use the key in LB like this, here's how it can be done.

3 Likes

@peternlewis: You have given us some great macro Application triggers. Adding "Application Gets Keyboard Focus" could be very useful.

I don't know of any way to detect that unfortunately. If I figure it out, I would probably (eventually) add it.

Very nice, @gglick. I’m so tempted to purchase LaunchBar. I’m very happy with Alfred, but little things keep cropping up that make me think "that’s neat".

Although, if I recall from reading the Wiki and a couple of posts from @peternlewis, does the final action that simulates a semicolon keystroke not present a potential risk of initiating this macro too, perhaps even into an infinite loop ? I’m assuming this wasn’t the case during your testing, but does this predict the behaviour on other people’s systems ?

More a point to ponder than anything. Obviously, the OP can just try it and see. Perhaps an alternative action would be to insert text by pasting.

It all comes down to what I call criteria.

Thanks, @CJK. For the record, I use Alfred and LaunchBar together. I find they each have strengths and weaknesses that complement one another, so whatever is tempting you about LB, I think chances are good you'll find a place for it alongside Alfred.

Regarding the semicolon key accidentally looping the macro, this was indeed not the case in my testing, and I imagine it would work out fine in practice on most other Macs as well, but you're right, it would be safer to insert it via pasting instead.

I am using this pass-through method also in a couple of macros (e.g. this one), and am not experiencing any loop issues. So far.

But in case the OP does have loop issues, then there are two potential solutions in this thread:

  • Using an USB Device Key trigger … does not work for me. The trigger does not get intercepted and thus LaunchBar receives both the trigger and the simulated keystroke: ;
    Not sure if this has always been like this (?)

  • Disabling/enabling the macro before/after the pass-through keystroke does work:

49-pty-fs8

But, as others already have said, due to the overhead and possible slowdowns I wouldn’t use such a macro for everyday keystrokes like ;. (It might be OK for triggers that contain a modifier key, for example ;, or if the macro can be put into an application-restricted macro group.)

1 Like