Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Mark Booth

macrumors 68000
Original poster
Jan 16, 2008
1,664
501
I'm posting this in the Sequoia forum because I believe the issue is related to security "features" in Sequoia.

Details: New Mac Mini (M4) running Sequoia 15.5 (all of the latest security updates installed). An AppleScript, running in Script Editor, that opens the Terminal app and sends 3 commands (keyboard entry) will sometimes run perfectly & other times will not run (due to keystrokes permission error). A standalone app made from the script will also sometimes work perfectly and other times not. The latest version of Python3 is installed on the Mini.

The standalone app is needed so I can make it a login item and run the script if there is a power failure and the Mac Mini reboots.

The script was working PERFECTLY (both in Script Editor and as a standalone app) on a previous Mac Mini (2014 Intel).

This is the script:



delay 30

tell application "Terminal"
activate
end tell

tell application "System Events"
keystroke "cd pigs"
key code 36
end tell

tell application "System Events"
keystroke "sudo python3 pigs.py"
key code 36
end tell

tell application "System Events"
keystroke "[Mini administrator password]"
key code 36
end tell


  1. When launched, the script waits 30 seconds before opening Terminal. This is to allow the Mini time to fully reboot after a power failure.
  2. Script opens Terminal.
  3. Script changes Terminal’s command line to the “pigs” directory (folder). The pigs folder is in my user account directory.
  4. Script runs pigs.py (which is a python script).
  5. A sudo command requires the administrator’s password, the final step enters that password.
I realize that virtually no one else will have a pigs directory or the pigs.py script on their Mac. But other directories and/or programs could be substituted for testing.

Again, sometimes this script works, other times it doesn’t. I cannot figure out any rhyme or reason nor any common situation that explains why it will sometimes run. It’s like a roll of the dice. Again, it worked PERFECTLY (for about 10 years) on my previous Mac Mini (older OS).

These are the errors that pop up when the script chokes. First, when it is run in the Script Editor and chokes:

i-76ZxVHX-X2.jpg



This is when the standalone app version chokes:

i-p3k5G8c.png



Both apps have the necessary accessibility:

i-cGFWN7r-XL.jpg



Right after it chokes, I can run it again and it might work (no error). Sometimes it works, sometimes it doesn’t. VERY weird! When it fails, it is failing at the very first keyboard command (“cd pigs”).

I spent about 40 minutes on the phone with Apple Support. I screen shared and they bumped me up to a higher level support rep twice. Final outcome: they had no idea what the problem might be.

The fact that the script sometimes works and sometimes not sure seems like an issue with the OS. Yet, nobody at Apple seems to care.

Any help or suggestions are much appreciated!

Mark
 
  • Like
Reactions: Starfia
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.