Suddenly getting 'Keyboard Maestro Engine got an error: Connection is invalid' errors

I run Mac OS beta and upgraded to 12.5 Beta (21G5063a). I suddenly started getting 'Keyboard Maestro Engine got an error: Connection is invalid' errors when things like "tell app 'Keyboard Maestro engine' to set somevariable to getvariable 'externalvariable'". It threatens to bring me to my knees as I've got lots of daily scripts I depend on...which makes you wonder why I run Mac OS beta on an important machine, but that's the topic for another post.

(Alternatively I get 'An error of type -25133 has occurred.' or with Filemaker trying to call KM scripts, "Unknown Error -609.")

Update: I wonder if this is a KM thing, or a general Applescript blow-up. When I run a simple Applescript that says

tell application "System Events"
	set listOfProcesses to (name of every process)
end tell

I also get a Finder got an error: Connection is invalid error. So...can anyone give me general advice for this situation? I tried unclicking Automation permission for all apps that had requested it, and then clicked them on again, then I restarted. Nothing seems to want to make Applescript commands (including KM run ones) work.

I’ve seen this and it is an AppleScript thing, not a KM issue. For me, it happens when the application/process my AS scripts are ‘talking” to are heavily-loaded or my system is running slowly for some reason.

The technique I use to overcome the error is to enclose the relevant parts of my AS in try…catch clauses so that the error is trapped and doesn’t result in the script just crashing out.

In fact, one particular script of mine was giving so many if these errors that I nested 5 try…catch clauses with delays in them to give the target app a chance to catch up with what my script was trying to do.

I’m not at my Mac right now so I can’t give you an actual example of the code but I hope this has given you an idea of what steps you might take to address the problem. The other thing you’ve alluded to is the beta OS: enough said!

BTW try Googling the actual error message text and you should get pointers to “defensive programming”.

1 Like

Thanks for the reply. Not sure if it's going to be solved by something like that. It seems like the beta I installed just borked everything. I tried making a separate user and, with nothing loaded, tried the scripts that were giving errors in my normal login, and they are all here. Looks like I might need to backup and reinstall the OS which is never fun.