You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript auto clicker script

I am trying to create a script in Applescript that would allow me to automatically click on 2 different locations on my screen, with half a second or so intervals between the 2, and repeat that multiple times.


So basically I would need to click a tick box to select a project, and then click an "Accept" button.


I have now gone through countless forums but were unable to find anything remotely similar. I am quite new to Applescript, so I would really appreciate some help. Thanks!

MacBook Air 13", macOS 10.15

Posted on Mar 30, 2020 4:05 AM

Reply
Question marked as Top-ranking reply

Posted on Mar 30, 2020 10:12 AM

I suspect the reality is a little more detailed than you describe. There are a lot of details missing that could make a big difference in the approach.


Generally the best practice is to identify the objects (check boxes, buttons, etc.) you want to click on, rather than click at specific x,y coordinates. Things move around on the screen - Windows might be in different places, scroll bars might be at different points, even the content in the window may change. Targeting the object, though, depends on the application in question.


If it's a web page the best idea is to examine the page's HTML and craft a JavaScript to do the work - that's one of the core competencies of JavaScript. If it's not a web page then you should look at the application in question and check its dictionary for what AppleScript support it has. Failing that, fall back to UI scripting, with all the caveats associated with that.


At its lowest level, this will do literally what you ask, but I maintain there is a better way of doing it:


set loc1 to {500, 600} -- x, y coordinates

set loc2 to {1200, 90}


repeat 1000000 times -- that's 'multiple times', right? :)

tell application "System Events"

click at loc1

delay 0.5

click at loc2

end tell

end repeat

4 replies
Question marked as Top-ranking reply

Mar 30, 2020 10:12 AM in response to Ktoff

I suspect the reality is a little more detailed than you describe. There are a lot of details missing that could make a big difference in the approach.


Generally the best practice is to identify the objects (check boxes, buttons, etc.) you want to click on, rather than click at specific x,y coordinates. Things move around on the screen - Windows might be in different places, scroll bars might be at different points, even the content in the window may change. Targeting the object, though, depends on the application in question.


If it's a web page the best idea is to examine the page's HTML and craft a JavaScript to do the work - that's one of the core competencies of JavaScript. If it's not a web page then you should look at the application in question and check its dictionary for what AppleScript support it has. Failing that, fall back to UI scripting, with all the caveats associated with that.


At its lowest level, this will do literally what you ask, but I maintain there is a better way of doing it:


set loc1 to {500, 600} -- x, y coordinates

set loc2 to {1200, 90}


repeat 1000000 times -- that's 'multiple times', right? :)

tell application "System Events"

click at loc1

delay 0.5

click at loc2

end tell

end repeat

Apr 12, 2020 7:59 AM in response to Camelot

I know the thread isn't for me, but I've been struggling and that code isn't working, it would work on the browser, but only one of the clicks worked, when I would take it to an application it just doesn't click at all, I'm looking to click on 2 locations where the locations won't change at all, and the interval between them would be pretty short.


Thanks,

Applescript auto clicker script

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