Trigger on application launch triggering unexpectedly (translocated apps again)

As a mobile app, Overcast always launches in the same inconvenient size and position on the Mac, so I made a simple macro to automatically move and resize it. And because it's a translocated app, the trigger has to be matched by bundle ID. What happens, though, is it will trigger unexpectedly and often. Initially, I 'solved' this by adjusting the timeout cancellation to 30 seconds. This prevented duplicates of the running macro building up, but it was bugging me that it was still triggering so often when it oughtn't to be.

So I tried another simple solution that I thought should work, which was to use the Try/Catch action and the All Running Applications token (and I've only just this moment noticed the All Running Foreground Applications token, which would be better) to check whether Overcast is in fact running. That check is much faster than waiting for the 30-second timeout to cancel the macro, but it doesn't always fail when it ought to...and that's what has me confused now.

Admittedly, this isn't a huge issue, but it is still bugging me. Any thoughts appreciated.

Macro screenshot (sorry it's a little messy—I was testing some more)

Engine log (incidentally, is there a reliable way to paste/upload png images to the forum?)

You haven't got a background app called Hovercash, have you? :wink: I suspect your regex is looser than intended -- tightening that up and moving to %Application%Foreground% may be enough to solve your problem.

That could well be since I don't understand regex at all :sweat_smile: I just repeated what I was able to make work in another of my macros.

I figured hovercash was a joke, but I still checked anyway, and nope nothing in the background applications by that name.

I obtained Overcast from the App Store to try a few things out.

I can confirm that Keyboard Maestro flags Overcast as a translocated application – but I'm not sure that it really is. :thinking: Moving Overcast out of the Finder and back again doesn't make any difference, and of course a direct download from the App Store installs an app straight to the Applications folder, where it belongs, anyway. Running sudo xattr -rd com.apple.quarantine /Applications/Overcast.app in the terminal should clear a translocation quarantine flag but results in "Operation not permitted" for the files inside the app bundle.

In any case… I had no problem with the following:

  1. Create a macro group that is set to be available only to Overcast.
  2. Create a macro that uses the Manipulate a window action.

For example, this worked for me:

Before:

After:

I tested under KM 11.0.3, MacOS Sonoma 14.7.1.

I have tried a few other tests, but so far, the only oddity I see is that Overcast is flagged as being translocated.

Many thanks for this. I did originally start out with a hot key trigger to resize and reposition the app window, but that got old very fast, which is why I changed it to trigger on launch. And the macro as is doesn't have any issues at all triggering when it's supposed to; it just keeps triggering when it isn't supposed to and I'm uncertain as to why.

Ah right… I can confirm the problem now!

This works for me:

Change "Front application" there to "Overcast" for a bit of added safety. :umbrella:

Many thanks again. But as I said, my macro is already working when expected. The issue is that it keeps triggering unexpectedly when Overcast has not actually been launched.

I know, but mine won't… so will it not suffice?

Looking back at your first post:

It looks to me as though your macro is testing for (1) the front window of Overcast + (2) the running applications list – without specifying that Overcast should be the active application. This could lead to false activation. Also, if test (1) is valid, test (2) should be superfluous.

For my screenshots in this thread, I just used the standard Mac shortcut ⇧⌃⌘-4 and then dragged the png into the message box.

In my experience, when the app is shown with (⚠️ Translocated!!), Keyboard Maestro's link to it is lost once the app is quit, so this method would require relinking the translocated app to the trigger every time, which rather defeats the purpose. I fought with this a lot already in a another macro for a different translocated app.

My macro tests whether Overcast is actually running by checking if overcast appears in %Application%Foreground%. If it doesn't, then the macro should cancel, which it does—sometimes. I don't see how this test could possibly result in a false positive based on whether it's in front or not. If Overcast is running, the rest of the macro works as intended. There is no second test; the Pause Until action is necessary because mobile apps can take longer to launch, and, because the launch time is variable, Pause Until is more reliable than Pause for x seconds.

I'm sure that @Nige_S is correct and that the problem lies in my regex.

Thanks, yeah, I use the same shortcut. I didn't ask that question very clearly, but the forum usually (though not always) converts the png to jpeg, which means a lot of ugly white space rather than nice, clean transparent backgrounds.

For me, that is not happening in this case. My macro has worked every time.

Your regex expression "overcast*", with the asterisk, is a match for "overcas" followed by zero or more appearances of the letter "t". "Overcast" would do just as well.

But anyway… I think you may have misunderstood try / catch a little. Your Cancel Just This Macro action is what happens when there is a catch, sure.. but the catch only happens if the try fails. When conditions result in false rather than true, that is not a failure. It is just one possible result. If there is something that the macro tries to do but cannot, that is a fail.

One such failure could be a timeout.

Right, the macro not working has never been the issue. The macro will continue to work when the app is actually launched; however, the macro will then carry on triggering randomly when it isn't supposed to. If you look at the engine log in my first post, you'll see that the macro triggered repeatedly thinking Overcast was launched when it wasn't. This was a problem before using Try/Catch and regex; I eventually added these actions in an attempt to make a better solution than just timing out since the Keyboard Maestro icon can get rather distracting always telling me that a macro is running when it shouldn't be for 30 seconds and then I have to check to make sure some other macro hasn't broken or run out of control.

Ah-ha!! So it does! I would swear that I tried that previously without success. Regex is new to me, so I've been searching and reading and experimenting with varying results. This could well be the solution, and I'll keep an eye on the logs for a day or so to be sure.

When I was testing, the try consistently failed at the Search Variable action if overcast didn't exist in %Application%All% (this was before I found %Application%Foreground%), but perhaps this is not the best way to force a failure. Though hopefully now with the correct regex and %Application%Foreground, it will behave a little better.

@kevinb's already explained why it is a bit loose. If the app is called "Overcast" then search for exactly that:

(?m)^Overcast$

"Using the multiline option so that ^ and $ match line beginnings and endings respectively, find any line that is exactly Overcast."

In this case it is -- when the regex action fails (false if we were using an "If" action) to find a match it throws an error and we're off to the "Catch" block.

Neither can I -- but it can be difficult to tell from only screenshots. Can you upload the actual macro so we can check the various action options?

Sure, but I was specifically addressing "Keyboard Maestro's link to it is lost once the app is quit", which I did not find to be the case with my test macro.

In case you don't yet know about it: regex101 is very useful.

Ah! I see now.

And neither can I… now I understand the macro better. It turns out I am not as clued in when looking at a png as I am when looking at a macro in KM's editor. :upside_down_face:

Super! Thanks so much for this.

Sure thing. This is what I get for thinking it was too simplistic to upload.
Overcast- Position Automatically.kmmacros (11.7 KB)

Fair, although since the primary question has been 'why does this macro keep triggering when it shouldn't?', I felt I should reiterate to make sure we weren't talking at cross-purposes, though I should have specified further for clarity. Threading the needle on giving enough information without being excessively verbose can be challenging for me.

Cheers

I have been trying your macro… and it has been working, with no false triggering. The log shows only the expected triggering.

The pause until action works fine with both or either condition; both are true when the macro is triggered by the launch of Overcast.

The macro fails as expected when triggered by a keystroke if Overcast is not running.

So… Hmm… Is is at all possible that your macro is being called by another macro, perhaps left over from your testing?

For the record: yes, this works fine, but so does trying to match on "Overcast" in this context.

1 Like

Agreed (limited testing).

The only reasons I can think of are that either for some reason Overcast is quitting/relaunching (ie it's a legitimate, though unexpected trigger) or that something else with the same bundle ID is launching (perhaps an Overcast-related background process?).

Check for the first by keeping an eye on what's happening, see if there's a pattern. That does assume that the "unexpected triggers" are unexpected because Overcast is already running.

If those "unexpected triggers" are firing when Overcast isn't running, hopefully the combo of only checking %ApplicationName%Foreground% and the tighter regex will help. What you could also try is a match against %ApplicationName%1% -- if the macro is triggered because Overcast launches, the frontmost application will be Overcast.

So you should be able to do something like:

Overcast- Position Automatically v2.kmmacros (4.1 KB)

Image

(You'll have to reset the "Execute Macro" action.)

Yes, but what worries me is something like "Overcast Helper", "Overcast-Updater", or similar are triggering the macro. I don't know if the bundle IDs of such sub-apps would be the same as Overcast's and so trigger the macro -- if so we need to make sure they don't false-positive the regex.

2 Likes

Good thinking – although Activity Monitor lists no process containing the string "Overcast" other than for the application.

Edit: so far as I have yet seen :stuck_out_tongue_winking_eye: