I have a friend that just had to replace an older Intel Mac Mini that was part of his Home Entertainment System. He had a script that ran on boot up that is described below. However it seems that due to changes in macOS, it no longer works properly, and Apple Tech Support is unable to help. I hope that perhaps someone here can come up with a possible solution. If more info is needed, I can relay the request to him..
Thanks
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 very 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
-
When launched, the script waits 30 seconds before opening Terminal. This is to allow the Mini time to fully reboot after a power failure.
-
Script opens Terminal.
-
Script changes Terminalâs command line to the âpigsâ (folder). The pigs folder is in my user account directory.
-
Script runs pigs.py (which is a python script).
-
A sudo command requires the administratorâs password, the final step enters that password.
I realize that neither you or virtually anyone 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:
This is the error when the standalone app chokes:
Both apps have been given the necessary permission (accessibility):
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â).
Any help you can provide is appreciated!