AppleScript "not allowed to send keystrokes" fix

TL;DR:

  1. Make significant code changes and recompile
  2. Then remove and add from System Settings > Privacy & Security > Accessibility
  3. Then revert those code changes and recompile back to what you want your script to do.
  4. 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

Posted on Oct 23, 2023 9:56 AM

Reply

Similar questions

3 replies

May 19, 2024 2:14 PM in response to rupertbreheny

Created a new script and set to run the normal way, but both scripts now got the error message. Had to do the trick above, but included both Apple Scripts also listed in that setting.


For good measure you could consider removing permissions and adding them back again in the Automation settings here:


Settings > Privacy & Security (Privacy) > Automation > {script_name} > System Events


When I did this I didn't need to recreate or rename scripts. It was just the turning off then on again of permissions for me, but exiting Settings app before re-enabling them again.

AppleScript "not allowed to send keystrokes" fix

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.