AppleScript "not allowed to send keystrokes" fix
TL;DR:
- Make significant code changes and recompile
- Then remove and add from System Settings > Privacy & Security > Accessibility
- Then revert those code changes and recompile back to what you want your script to do.
- Then remove and add from System Settings > Privacy & Security > Accessibility
Hi,
I hope this helps someone.
After upgrading to Sonoma, my AppleScript that sent keystrokes broke.
This is the same question as Apple script is not allowed to send keyst… - Apple Community but the solution there didn't work for me so here's how I got it working again.
I ran the code from Script Editor and discovered that some GUI elements had changed. In fixing that, I had to change the code to list the GUI elements that exist so that I could pick one. Once I did that and updated the script code with the new GUI element name and recompiled, the keystrokes started working.
# For reference, this code lists GUI elements of current window.
# Copy the output into a text editor and find/replace , with ,<Line Break> so each element is on a separate line
tell front window of (first application process whose frontmost is true)
set uiElems to entire contents
end tell