Why does Activate Screenshot cause a macro timeout?

I bound a hotkey to a script with a single action: Activate Screenshot. I press the hotkey and the screenshot comes up and I save the file. A few seconds later there's a notification "Macro Cancelled" timeout exceeded. Why? The action completed successfully.

I've never heard of the KM action Activate Screenshot

Please post your macro using KM's File > Share > Keyboard Maestro Forum

I wasn’t familiar with the File > Share > Keyboard Maestro Forum and after a few attempts it said "too many new topics on day one” or something.

My macro simply called the Activate macro selecting the Screenshot programme which is part of Ventura Macos 13.6. It allows you to select a portion of the screen, then when you press the Capture button it opens the image in Preview.

The "Activate specific application" action successfully completes when the app in question becomes "frontmost". But Screenshot never does become frontmost -- it's a background-only app! So the action runs until the end of its timeout period, then errors and the macro exits.

If all you are doing is that single action you can mess with the "Timeout" settings, found in the action's cogwheel "Options" menu:

These settings

...will let the macro complete and stop annoying notifications of timeout and failure.

Be careful though -- if you extend your macro to later do something with the captured screenshot you'll need to find a way to pause after this action until you're ready to go to the next phase.

1 Like

Is there a particular reason you need to use Apple's screenshot tool? KM has a built-in screenshot action with lots of options:

Capture to the clipboard, and you could then add a second action to save the clipboard to a file:

(Ignore the "With format" bit in the save; I just added the action and didn't edit it at all.)


1 Like

Thanks, now that makes sense.

Thanks — I’m fairly new to KM and didn’t know (or had forgotten!) about the builtin one.

The built-in one doesn't seem to have the ability to select an area. I see an action to select an area and set a variable to this, but the Screen Capture doesn't seem to allow this variable to be set; it seems to want it hard coded in the action.

That works nicely. Thanks for the explanation.

I'm not sure I fully understand, but if I do, I think you can do what you want. It just looks like it won't take a variable:

But it will if you just start typing in any of those boxes. As soon as you do, the dialog reformats itself:


Thanks - that would work if the area was the same the whole time. The Screen Capture program allows you select it on the fly, which is what I wanted.

Setting the timeout to 1 — and telling keyboard maestro to ignore it — fixed the problem.

Maybe you know this, but there might be some people who don't know this, so I'll mention it here. Technically, you don't need to create a KM macro to activate Screenshot, since macOS already allows you to define any shortcut key of your choice to activate it... The one that you want is the fifth one in the list below.

You don't have to use the default values. You can change the keyboard shortcut right on that screen, by double clicking on the shortcut (which isn't obvious.)

I'm quite used to SHIFT-CMD-5. I use it so often I can easily press that key combination without even looking at the keyboard. However I use it so much, maybe I should consider creating a single key macro for the action.

I assumed you wanted to pre-set the area, because that's all you can do with the Keyboard Maestro Screen Capture action. Let me explain why that is…

One of the best things about KM is its context-sensitive help. Click the Gear icon for the Screen Capture action, then select help, and you wind up here:


On that page, you'll see this:

Keyboard Maestro does NOT replicate OSX's interactive capture area functionality – e.g. 4.

Unfortunately Apple has not provided an API for that.

Therefore to use it in a script you need to use an Execute a Shell Script action:

screencapture -ic

This will capture interactively to the clipboard.

Enter “man screencapture” in the Terminal.app for more information.

So if you want interactive capture, that's how you have to do it. I'm not sure what was happening when you set the timeout to 1, but it can't be the KM action doing the work, based on the above. @Airy, though, has the best solution, which is to just set a global keyboard shortcut that you like, and you don't even need KM involved.

But if you want KM involved after you take the screenshot, then you can use the Clipboard Changed trigger:

Your macro could then look at the clipboard and do whatever it is you want to do to it. Note that if you go this route, you'd also want a way to insure it only works when you want it to, because the macro will fire every single time you copy something. I have a similar macro, and the first action it takes is to check that the clipboard contents are text and are the specific type of text I want to take action on.


Thanks, everyone, for the feedback. I've learned a lot!

OP was using a KM action to launch the Screenshot utility -- Screenshot is a background only app, so never becomes frontmost, so the action never completes successfully. That's why setting a short timeout and ignoring the resulting error fixed the problem.

There's advantages to using Screenshot over the builtin action or CLI alternatives -- more choices at execution time and thumbnail preview to name but two.

1 Like

Ah, sorry I missed that the first time. Thanks!


1 Like