Window not activated using open kmtrigger from terminal with Bring Window To Front

I have a very simple test macro named ExampleRed that just does Bring Window With Name Containing “Red” To Front in Finder (see screencast link below).

When I run it from Keyboard Maestro is properly brings the window to the front and the window stays active.

When I run open kmtrigger://macro=ExampleRed from Terminal the window is brought to the front, but then somehow deactivates. This means I can’t do follow on actions like sending it text (or typing from my keybaord). I have tried adding additional actions like Bring Window To Front Front Window in Front Aoplication, but it still stays deactivated.

In my example I am just using FInder and calling open from Terminal. But my goal is to use it with other windows (e.g. Chrome) and calling open from other tools (iTerm2).

Here is a screencast http://screencast.com/t/3lgwuXgt.

Any thoughts?

Thanks,
dave

Have you tried using “Activate a Specific Application” to activate Finder, either before or after bringing the window(s) to the front?

Hey David,

I believe what’s happening is that Keyboard Maestro’s URL-scheme is activating the Keyboard Maestro Engine. This happens even when you add an Activate a Specific Application to the called macro.

Since the engine is a faceless app the user is left high and dry and doesn’t know it.

This appears to only happen when the the scheme is run from any terminal environment.

By contrast this AppleScript:

open location "kmtrigger://macro=ExampleRed"

Leaves the user squarely in the Finder.

I think it likely that Peter is using standard APIs for this, so it’s not a bug per se.

Keep in mind too that the URL-scheme is actually calling Keyboard Maestro.

Probably your simplest work-around is something like this:

open kmtrigger://macro=ExampleRed; open -a Finder

-Chris

Fixed for the next version.

Thanks for the fix, Peter.

However, I'm not sure exactly what has been fixed, and what the new behavior is.
Could you please provide some details when you get a chance?

Thanks.

When the Keyboard Maestro Engine gets the kmtrigger:, the system automatically brings it to the front (as @ccstone correctly surmised), which takes focus from the previous application. Keyboard Maestro will now resets the focussed window back to the previous application.

1 Like

Thanks!