Catalina: How to add System Events to System Preferences > Security & Privacy > Privacy > Automation?
osascript -e 'tell application &quot;System Events&quot;' -e 'keystroke &quot;echo hi&quot;' -e end tell
will add an entry System Events under ther terminal emulator where you run it from in the automation section.

If you receive execution error 1002 again, uncheck and recheck System
Events under Automation again.
If you receive  execution error -1743: Remove the app from the Accessibility/Bedienungshilfen section and add it again

execution error: Not authorized to send Apple Events to System Events. (error -1743)
execution error: Keine Berechtigung zum Senden von Apple-Events an System Events. (-1743)


If you receive execution error -1719: Add /System/Library/CoreServices/System Events.app to Accessibility/Bedienungshilfen via 'Choose File' dialog

execution error: System Events got an error: osascript is not allowed assistive access. (-1719)



Possibly lock and unlock between rechecking/readding or run multiple times or prefixed by sleep 1 &amp;&amp;. These new security settings unfortunately still seem a bit messy (good links for further reading there!):

Hopefully this gets worked out before Mojave ships.

Nope :-(
By the way, osascript -e 'tell application &quot;System Events&quot;' -e &quot;keystroke key code 53&quot; -e end tell ran twice will add the entry for the program itself under the program.