Wrota an Automator app that sends chat messages for debugging purposes. It has the following Apple Script
on run {input, parameters}
repeat with i from 1 to 30
set message to "This is message #" & i
do shell script "osascript -e 'tell application "System Events" to keystroke "" & message & ""'"
do shell script "osascript -e 'tell application "System Events" to key code 36'" -- Press Enter/Return key
delay 0.1 -- Adjust the delay if necessary
end repeat
return input
end run
I gave it Accessibility permissions. After a couple of runs it fails with the following error
The action “Run AppleScript” encountered an error: “36:66: execution error: System Events got an error: osascript is not allowed to send keystrokes. (1002)”
What can I do so that macOS lets me run the script?