Delayed saving of macros

Why doesn't KM recognize changes in JavaScript right away? I have a bunch of Javascript I'm working with. Lets say I run a set of macros with an alert popup using Javascript. I change the Javascript alert text and re run the macro set and the alert doesn't change. Eventually it will change.

This is just an example and it is more involved than this. The alert I change text on is just so I can be sure I'm targeting the correct JS function. The more involved part is when I change the actual JS function things aren't reflected in the Macro right away. Eventually I can get it to update but sometimes killing the engine, quitting everything. Sometimes restarting etc.

Changes made in the editor are grouped together and saved after a short period of time (you can see the “dirty” flag in the bottom right corner of the editor window). Otherwise every character you typed would cause a disk save which would be slow and cause disk wear and battery drain.

If you click the Run button on the macro, Keyboard Maestro will force the macros to be saved first so consider doing that if you are changing a macro and immediately triggering it.

1 Like

Thanks, ya I am careful to at least click into another window after making a change and this seems to commit the XML change.

My question though was more regarding the reference to an external javascript library of functions. The macro just calls the function. However all the JS is in the external functions file. I can totally FUBAR the JS and save, and it will still run normally like I made no changes. Eventually it will "catch up". So KM has to be caching that JS somewhere.


Here is a sample of what I mean. The alert text in the JavaScript doesn't match the previous alert.

This is after shutting down KM and the engine and restarting. So somewhere that old javascript is being stored and called and not the updated. I just changed the alert as a marker to see if it changed when running the macro.

If you are using the Execute a JavaScript in Browser action and you are referencing an external file in the action, then Keyboard Maestro definitely does not cache the script. It reads the file directly, adds the various variables and then executes the script using AppleScript as text. There is no caching on Keyboard Maestro’s part.

If you are talking about the Execute JavaScript for Automation action, then Keyboard Maestro passes the script file path directly to osascript

So if that is the case, whatever is going on is going on somewhere else.

If you are using a different action, then you'll need to explain what you are actually doing.

I'm not sure what Ai is (Illustrator?) or how you are using JavaScript to interact with it, so maybe that is part of the confusion.

Yes AI is Illustrator. So we have a large functions.jsx library. They are called with something like this.


And ran with something like this.

The new.jsx is ran and trashed. The problem lies where I make a JS change to the function and this is not reflected when the macro runs. Eventually it will start working, but that isn't productive when you are testing different iterations of the JS code.

OK, you have two actions there, one that writes the text to the /tmp/new.jsx files, and one that executes the AppleScript.

If the two are executed in sequence, then Keyboard Maestro will write the file before moving on to executing the AppleScript. In that case, the only conceivable way AI executing the outdated file is if AI is caching the file.

If the two are not executed in sequence, then the question would be how and when is the first action running, and how and when is the second action running?

When and how is the file trashed?

File is trashed automatically as far as I can tell, possibly because the next jsx file is called new also, There is only one macro that runs the AI files and they all write to a new.jsx file name.

Interesting thinking that Illustrator might be caching the functions. All I really need is a consistent way of insuring the latest JS is being ran. And if that takes shutting down illustrator each time and reopening then that is fine.

If I can find the exact sequence I can just setup a macro that shuts down AI and reopens then does whatever else needed. This only happens in my dev environment, once it gets rolled out to production things are good. However there might be a little lag time until the production machines get the functions.jsx file synced up.

Why not use a unique file name each time. Instead of /tmp/new.jsx, use RandomUUID token to get a new name each time.

That should avoid any change to cache the file.

I thought the same thing too, but I'd need an AI macro for every named function. Now I don't like the new.jsx file name. But you can call it dog.jsx and it works the same. Sure for debugging I'd love my trash or temp files filled with properly named JSX files. But one macro set can run up to 40-50 functions so every one would need a unique name.

OK, I guess I don't really understand your overall process if you cannot write the JavaScript to a newly created uniquely named file and then execute that newly created file, and I'd wonder whether the area where I lack understanding of the reasoning/process involved in that is where the issues are actually coming from.