I'll admit I only skimmed this, but here's a question: Why do you need a JXA script to do this periodic timer thing? KM already allows you to trigger a macro on a timer. You can enable and disable the macro as needed.
@DanThomas Perhaps I should try to simplify my initial post. I will try to do so. Thank you for reviewing it and your reply!
I have been thinking about doing most of it in JXA and javascript and that was the reason. But your idea of enabling and disabling a macro is powerful and simple. And I might try that as an immediate fix.
I understand the thought of doing it all in JXA, I've tried that before. But I've learned to use KM as much as possible, and only resort to JXA when it is necessary, or will speed things up noticeably. With that said, I have a ton of JXA scripts.
By the way, the reason setInterval and clearInterval aren't available in JXA is because they're actually a method of the Window object, which is the context used in HTMLs javascript. Since you're not running in a browser, you don't have access to it.
However, if you were using it in a Custom HTML Prompt, then you'd have access to it. If you want to call KM macros from within the custom HTML prompt, see the Wiki Entry.
Also, as far as I know, you can't use Node with a KM Script action. (I think you mentioned that in your withdrawn post, but I could be wrong.)
Thank you for explaining how setInterval etc is not available because it is in the context Window object in a browser. Need to learn javascript etc somewhat more.
As for why the tendency to do more in JXA than in KM, it just feels like if I could do more in JXA and more in script, then making changes will be easier than making changes in KM. KM is very powerful of course.
So glad I found KM and this forum, and thank you again to you and others here who help so gladly. Have a wonderful day!