Selecting "Display results on a Window" Goes to Notification Center

I'm not sure if it's Monterey or KM 10, but KM now routes JXA output to notification center when selecting "Display Results on a Window."
It used to display on a KM window.
Is there a way to change it to old behavior?

That's a pretty surprising result. If you share the code with in this thread, I think I'd be willing to run it, to see if the problem is with the action itself or with your Mac's configuration. Have you tried if any other KM actions are doing the same misbehavior? How about the "Javascript in front browser" action?

You don't need anything special.
Put console.log("test") in JXA action.

Okay, I did that, and nothing appeared in the notification center. So I can't replicate your problem. That means the conclusion that "KM routes JXA output to the notification center" is probably incorrect, because it doesn't do that for me.

I was able to get the action to display its output in a window by checking the "Include Errors" flag for the action.

P.S. This was my first time ever using the JXA action, so thanks for giving me the code. Without that, I could never have done this test.

Thanks for testing. Actually I discovered something.
if there's no error, it displays fine on a window.
However, if script throws an error, it goes to notification center.
I tried both checking and unchecking includes error.
Could you try
No quotes around ok.
Thanks so much!

When I run that I get this error.

Screen Shot 2022-03-06 at 7.57.36 PM

To me that makes sense. Errors generate notifications. Is that not what you want?

Yea it used to output all the errors including console output in a new window not to notification center.
It looks like if there's no error, output goes to a new window, if there's an error, it goes to notification center.
Is there a way to go back to previous behavior?

If you want the errors to show up in the window, that's easy, just check this option: (change the X to a checkmark)


I don't know what happened in the past, but I do know that you can make the errors show up in the pop-up window by checking the option above.

So what is it that you can't do right now that you want to do?

Yea if you check include errors, it still goes to notification center.
I want so that, error goes to KM window window, not notification center.
Hope that makes sense.

It does make sense. I'm sorry for misunderstanding. Let me think about it.

I was searching for ideas in this website and found this quote:

we should ALWAYS (in JXA) wrap everything in a try/catch, then “return” the error message, rather than let the error bubble up via stderror, because we generally turn off “return errors” (because of the Yosemite issue), right?

Does it seem like a good idea? This might stop the error from going to the notification center.

That kind of works, but you don't get the full output with line number where the error is.
@peternlewis I wonder why the behavior changed?
Right now you can't debug if you have do not disturb on. lol

I guess it's time to ask him. I'm out of ideas, myself. I know there are some real JXA programmers on this site that may be able to help. @DanThomas ?

If the action fails and notifies of the failure, that failure appears in the notification center.

If the action does not abort the macro, then it will do whatever you request with the text results.

Control this in the gear menu.


The only change that might have occurred is that the action aborts if there is a failure of the script action that is reported back to Keyboard Maestro.

Thanks @peternlewis.
However, regardless the state of "Notify on Failure", KM routes script output to notification center if there's an error.
If you turn on do not disturb and run the following in JXA action, you won't see because the script throws an error on the second line.
Then if you comment out the second line like:
// console.log(ok)
and run, KM will displays the output to KM window because the script doesn't throw an error.
Is there a way to change back to previous behavior where both console output and debug information appear on a new KM window instead of notification center regardless script throws an error or not?

I'm not sure why you're seeing what you're seeing, but I'm guessing it's because you're not catching the error in your JXA script. Here's an example of how I do it. This is a stripped-down version:

(function() {
	'use strict';

	function execute() {
		// do the work here

		// Return whatever you want.
		return "OK";

	// #region ======== Runner Code =============================
	try {
		return execute();
	} catch (e) {
		return `Error on line: ${e.line}: ${e.message}`;


Here's how I use it in context:


Here's the macro:

JXA Template Example.kmmacros (5.9 KB)

No it doesn’t.

Turn off Abort on Failure.
Turn on Include Errors.

@peternlewis, thanks so much! Failure aborts macros was the key!
One more thing though. Even with includes errors on, it seems like it truncates the debug message?
If I just put the following in JXA
and run, I get
It used to output line number and report what the error is about.
If I put the same things on a file and run in terminal,
osascript -l JavaScript test.scpt
I get
test.scpt: execution error: Error: ReferenceError: Can't find variable: ok (-2700)"
Thanks for your help!

Maybe. I'll take a look. Sometimes when a script fails it may collapse before flushing all the output.

This should be resolved in the next version.

1 Like