Trigger Only if a Certain Application Is Frontmost

I have a ultra wild monitor, with two windows of safari, and one window of TextMate.

All the windows are displayed, but I would like my macro to run only if the current app active = TextMate (the one showing in the menu bar)

I tried

tell application "System Events"

set activeApp to name of first application process whose frontmost is true
end tell
if TextMate is in activeApp then
##myscript
end if

but this is only working with AppleScript but not within KM

I also tried KM "if then else" statement but that don't work neither.

This should work:

  1. Set the Macro Trigger to when TextMate Activates:
    • image
      .
  2. To Make Sure TextMate is FrontMost, use this IF/THEN:
    • image

Note that this Macro will Trigger ONLY once when TextMate is first activated.
If you want to use it while already activated, you will need to add another trigger to the same Macro.

If your Macro is still not working, please post your Macro.
See How to upload your macro. Instructions for uploading to an existing post are just below the main instruction.

I may be slow, but why wouldn't you just use a macro group that's only active when TextMate is active?

Because the Macro would NOT trigger when TextMate is NOT frontmost.
This macro is designed to trigger (in a Global Macro Group) when any other app is front most.

OP asked:

Maybe I'm missing something?

If TextMate is already frontmost, then you can NOT trigger on it being activated.
In that case you need to use another trigger, lke a HotKey, as I stated:

That is all very true. And perhaps the OP can be read a couiple of different ways. I see it as "I only want this macro to run if Texmate is active. Hence the suggestion of a macro group.

Thanks a lot, I thought I tried that before but obviously I most have missed something.
it's seems to work perfectly now. thanks for your help and sorry if my post was confusing at the first place.

1 Like