Trigger when open app window?

If I close an app by click the red cross on the top left corner, the app windows closed but the app itself is not quitted, then I click the app on the Dock to open it again, how to add a trigger for this? I know I can use application activates trigger, but this trigger is triggered whenever the app window is focused, not really what I want.
Thanks.

It is not clear exactly what you do want.

At exactly what point, what event, do you want the KM Macro to be triggered?
What is the purpose of the macro being triggered?
Does it need any app windows to be open?

Please read:
Tip: How Do I Get The Best Answer in the Shortest Time?

Here is an example. I often use the red close button on the top left corner to close app window. See below image for Chrome after I closed it. The app is not quit (there is dot below the icon), just window closed. Now when I click it to open a window, I want to trigger something here. So basically it is the first window of the app. "Launches" doesn't trigger it. "Activates" will trigger, but this triggers whenever the app window gets focused.

Screen Shot 2021-03-20 at 10.15.20 AM

You can create TWO macros:

One macro that sets a variable "CountChromeTabs", that runs when you deactivate or switch apps

And another macro that runs when you Activate Chrome and checks the previously stored variable:

you can then suit to your specific needs

1 Like

You can use the "Activates" Trigger with an IF/THEN Action.
This works for me running Keyboard Maestro 9.2 on macOS 10.14.6 (Mojave).

NOTE: This assumes that you have configured Chrome to open with a new tab/window. If you have set it to open with one of the other choices, then you will need to adjust.

image

As an alternative, you can write a macro triggered by something else, like a hot key, that checks Chrome for the number of its windows, and then only continues the macro if that number is zero.

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Chrome Was Activated with No Windows From Dock [Example]

-~~~ VER: 1.0    2021-03-20 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Chrome Was Activated with No Windows From Dock [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


2 Likes

So here is the macro that I would use.
IMO, it is more reliable, but does require that you use a Hot Key trigger (or something else). It does not matter how you have configured Chrome to open.

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Run Macro IF Google Chrome Does NOT Have Any Windows

-~~~ VER: 1.0    2021-03-20 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Run Macro IF Google Chrome Does NOT Have Any Windows.kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


1 Like

Thanks all and I learned new things (always). Really appreciate all the help!

1 Like

@henryone, if one of the above posts solved your problem, please check the "Solution" checkbox at the bottom of that post.

1 Like