Assistive access for osascript

I have been trying to use osascript to run a GUI-scripting Applescript in the background. The GUI-scripting action the Applescript performs is to click on a TextEdit menu item. It always worked in the past, but now I get the following error message:

I added /usr/bin/osascript to the assistive access database as described in this post: osascript does indeed show up in the System Preferences Security & Privacy pane as enabled, yet the error message continues to occur when I try to execute the osascript.

I found several discussions on the web describing this very problem with assistive access for osascript, but could not find any solutions.

I would be most grateful for any ideas about how to grant assistive access to osascript.

I discovered the problem. The osascript command was being executed by a non-code-signed application. After I recently edited that application (even though I didn’t change its name), it evidently looked like a new application to the Assistive Access registry, as is discussed in Apple’s documents. After re-inserting/enabling the application in the registry, the error message no longer pops up.

It was confusing that the error message claimed that osascript is not allowed assistive access, whereas in reality it was the application executing the osascript command that was lacking assistive access.