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,665
502
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
Glad it works, but what exactly does the python DNS restart script do? If it’s modifying macOS DNS settings, you may not need Python and sudo at all. The built-in networksetup tool can change DNS settings for Ethernet and Wi-Fi without requiring an administrator password.
 
Glad it works, but what exactly does the python DNS restart script do? If it’s modifying macOS DNS settings, you may not need Python and sudo at all. The built-in networksetup tool can change DNS settings for Ethernet and Wi-Fi without requiring an administrator password.

It's not messing with my network's DNS settings at all. The story:

Once upon a time, Channel Master (the TV antenna company) offered an over-the-air DVR called the DVR+. Which, of course, worked similarly to a cable box but got its signal from an antenna instead of from cable. It came with a FREE program guide (via the internet). Unfortunately, after a few years, Channel Master abandoned the program guide feature and, without it, the DVR+ was basically useless.

Enter some clever fellows on AVS Forum. They came up with a Python script that was intended to run on a Raspberry Pi in conjunction with a program guide available via Schedules Direct. On a daily basis, the Python script downloads your personalized program guide for the next 2 weeks (meaning, daily, it updates one more day and adjusts for any changes in the schedule from the day before). In addition, DNS settings changes are made to the DVR+ so it is looking for its program guide at your own network (a fixed IP for the Mini).

Since I have a Mac Mini that is on 24/7 and the Mini can run Python scripts in Terminal, I adapted the Python script to run on the Mini. It ran perfectly for 10 years on my previous Mini and, while the Python script also runs on the new M4 Mini, what wouldn't work on the M4 Mini was the Apple Script I created to automatically run the Python script after a power failure.

Schedules Direct costs $35 per year. A very fair price to have a high quality program guide. Channel Master *could* have set up a program guide on their own servers and then had DVR+ owners change the settings accordingly, but they are too cheap and lame to do something like that. Those of us who purchased the DVR+ were promised "lifetime" channel guides. Yeah, right.

Anyway, you saved the day, so thank you!

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