KM launching Alfred

I absolutely love KM and ever since I have started using it, I have been trying to streamline most of what I do on the Mac through it. One of the things I have streamline is hotkeys. The added functionality that KM provides to a single set of hotkeys is unbeatable. Multiple clipboards for example, provides a whole new set of applications for cmd+C and cmd+V. But back to my original question, I now use KM to launch Alfred (Launcher/Productivity App) using a hotkey trigger which in turn launches Alfred either by using its own hotkey trigger or an applescript. The problem that I am encountering is in between the time the macro starts and Alfred launches, which is a fraction of a second, any additional keystrokes after the trigger are not getting passed over to Alfred. Such as, let us say I would like to search google for something. When using just Alfred, I would trigger it using its own hotkey trigger and then immediately start typing “google” and “google” would appear on Alfred’s search bar. Now when using KM to trigger Alfred what ends up happening is Alfred launching with just “oogle”. I assume the missing “g” is due the time KM requires to process the macro and considering this I was wondering if there was a way to resolve it or possibly have the macro record the keystrokes after the trigger and then insert them once Alfred appears?

Thanks in advance for you help.

Might I suggest that, in the future, you break up your post into multiple short paragraphs? It’s a little hard to wade through a single, long paragraph - especially when your question is clear at the end. It would help.

Anyway, regarding your question. Assuming I read it correctly, it sounds like a timing issue. There’s a couple of ways of handling this.

The simplest (at least to me) is to add a Pause action immediately after your action that launches Alfred, before inserting “Google”. Probably something as short as .3 or .5 seconds is enough, but you can experiment.

Another possibility is that, instead of a Pause action, you can add a “Pause Until” action that waits for Alfred to become active. That may or may not work, depending on how Alfred works.

Let us know if that helps.

Thank you for the feedback and the suggestion.
I will make sure to break up future posts.

Considering the suggestion, adding a pause actually causes the behavior to be worse; ignoring more keystrokes such as a pause of 0.5 passes “ogle” to Alfred. The way I have been presently working around it, is to physically wait for Alfred to appear before starting to type what I would like Alfred to search, but it is a bit of delay since If I was to trigger Alfred directly there would be no noticeable delay between the hotkey trigger and the search term. Thank you for looking into it.

Can you post an image of your macro? Perhaps that will help diagnose the problem.

I’ve tried your macro, and it launches Alfred’s search box pretty fast, in my view. Only if I start to type really immediately after pressing the hotkey I can reproduce the problem with the first character missing.

I think there’s nothing you can do about it. What you are doing with the macro is rerouting the launch of the Alfred box through KM and AppleScript. This explains the slight delay.

To avoid this delay, and to launch the Alfred box as fast as possible, you should just use the native Alfred shortcut, without any rerouting.

I think the main purpose of Alfred’s “search” AppleScript command is to pre-populate the search box with text, for example tell application "Alfred 3" to search "os x ".

By the way:

I wouldn’t use the Option key alone as hotkey modifier. Unlike as with other operating systems, on the Mac the Option key is not a “meta” key. It serves as character modifier, similar to the Shift key. The key combo ⌥ Space is used to type the No-break Space character (U+00A0) in almost every program that accepts text input.

If you assign this combo as a KM hotkey you are no longer able to use it for typing the character.

Tom -

Thanks for posting your reply. I had thought, for some reason, that the macro was typing in Google, not the OP himself. So of course, my idea of adding a delay would serve the opposite effect, as it did. I was kind of stumped.

Yes, I struggled, too, to understand what the OP wanted to achieve. I think what he’s trying to do is to replace native shortcuts of other apps with KM shortcuts, with the goal to “collect” all shortcuts in one place (= KM).

1 Like

Thanks for looking into it. This was also the conclusion I was arriving at but thought their might be another way. Is it possible to record what is typed after the trigger into a variable and then re-insert it into the applescript?

Thank you for the additional tip.

That is exactly what the OP is trying to do. You can add a lot more functionality to the native shortcuts using KM then the native applications provide.

Thanks again.

Not sure what you mean. You can insert a User Prompt action into your macro, then type the text in there. When you press Return the text will be stored in a variable. You can then access that variable in the AppleScript.

What I mean is to have KM capture all keystrokes after the trigger is pressed. If this would be possible, then I could use it use the captured keystrokes to re-enter the missing characters in Alfred after it appears.

This starts to go around several corners now :wink:

You are asking for a keystroke logger that is triggered by the hotkey of the macro. Then the macro (or the AppleScript) should have knowledge of what keystrokes are missing in the Alfred box, in order to insert them, presumably when you have stopped typing.

I don’t see how this could be done, and —unless I’m completely misunderstanding— I don’t see how this would make much sense, in relation to the effort.

I would give the User Prompt action (see my post above) a try. This way you won’t lose any keystrokes and, if you add a Return keystroke after the AppleScript, you don’t have to press Return twice.

Maybe somebody else has a better idea?

@CloudTetraVie I was already formulating my thesis on the problem when Tom responded. I agree with what he said.

I think you are adding steps to a process which could be distilled down to much less. Another thought that comes to mind is: Are you using the right tool for the job? I haven’t used Alfred but I wonder if it doesn’t already offer the end result you are seeking?

I use Launchbar with great results to do exactly what you are trying to do with Keyboard Maestro and Alfred. Keyboard Maestro is the greatest though.

I intended to give your suggestion a try. I was only looking for a way to get around the slight initial delay and the initial thought was to use the keylogger approach, but indeed it may be too much effort for what it is worth.

Alfred does indeed already offer the end result I am seeking, but as mentioned on a pervious post, I am looking to have all native shortcuts handled through KM since KM provides additional functionality. If Tom's suggestion doesn't work I will return to just managing Alfred directly.

Thanks everyone for time and looking into it.