Wednesday, November 13, 2024

automator – My automated “click” Applescript has just stopped working

Right up until a week ago, my simple Applescript that had to simply click on a specific coordinate on screen just stopped working.

Here is the Applescript:

tell application "System Events"
click at {693, 619}
end tell

And I automate it’s trigger at a specific time of day with the help of osascript (recommended for Applescripts) using the following plist file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.mouseclick.plist</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/osascript</string>
        <string>/Users/mugenvoid/Downloads/mouseclick.scpt</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>6</integer> <!-- Adjust the hour as needed -->
        <key>Minute</key>
        <integer>10</integer> <!-- Adjust the minute as needed -->
    </dict>
</dict>
</plist>

I’ve added this plist file to the LaunchDaemons folder of my core Library folder. This will ensure it’s a global daemon, so it should have the highest chance of always triggering correctly. Beyond that, I’ve given all the relevant access and permissions (Accessibility, Automation, disk access etc) for this setup to work correctly.

To ensure the job is loaded correctly and functional, I use an application called Launchcontrol 2. Over there, it is always loaded in correctly and the status shows as OK.

Despite all these checks and balances, the script just doesn’t click on the specific coordinate no more. It was always working perfectly fine up until a week ago and I haven’t made any changes whatsoever to this whole setup.

The Launchcontrol 2 application has some launchd(8) logs of the job trigger event at the designated time that I would like to share. Perhaps it will help with the debugging. Here it is:

2024-10-22 06:10:03.808584 <Notice> internal event: WILL_SPAWN, code = 0
2024-10-22 06:10:03.808688 <Notice> service state: spawn scheduled
2024-10-22 06:10:03.808692 <Notice> service state: spawning
2024-10-22 06:10:03.808727 <Notice> launching: xpc event
2024-10-22 06:10:03.810543 <Notice> xpcproxy spawned with pid 28683
2024-10-22 06:10:03.810593 <Notice> internal event: SPAWNED, code = 0
2024-10-22 06:10:03.810599 <Notice> service state: xpcproxy
2024-10-22 06:10:03.810718 <Notice> internal event: SOURCE_ATTACH, code = 0
2024-10-22 06:10:03.827675 <Notice> service state: running
2024-10-22 06:10:03.827703 <Notice> internal event: INIT, code = 0
2024-10-22 06:10:03.827709 <Notice> job state = running
2024-10-22 06:10:03.827726 <Notice> Successfully spawned osascript[28683] because xpc event
2024-10-22 06:10:10.104597 <Notice> exited due to exit(0), ran for 6293ms
2024-10-22 06:10:10.104617 <Notice> service state: exited
2024-10-22 06:10:10.104630 <Notice> internal event: EXITED, code = 0
2024-10-22 06:10:10.104633 <Notice> job state = exited
2024-10-22 06:10:10.104665 <Notice> service inactive: com.mouseclick.plist
2024-10-22 06:10:10.104681 <Notice> service state: not running

To the best of my knowledge, I’ve checked everything possible from my end and am still faced with this roadblock. I’d really appreciate your support here!

Condensed view of what I’ve tried so far:

  • Under the Privacy & Security settings section, I enabled
    Accessibility for osascript, launchcontrol and the script editors
    I’ve used for the Applescript and the plist file. See image attached
    below. Accessibility Settings
  • Under the Privacy & Security settings section, under Automation, the
    requisite access has been given to Osascript and relevant
    applications. See image attached below. Automation Settings
  • Ensured the job is loaded correctly with no errors and that it is
    loaded in as a global daemon (by adding the plist file to the
    LaunchDaemons foler in my core Library folder). See image attached
    below. Launchcontrol 2 job view
  • Verified the script file and plist file and found no syntax errors
    (code used for both has been shared above).
  • Ran the script file from the Script Editor itself to confirm if it’s
    working fine and got the following results. See image attached below.
    Script run results

Related Articles

Latest Articles