Auto Clickers

Joined
Oct 16, 2010
Messages
17,496
Reaction score
1,541
Points
113
Location
Brentwood Bay, BC, Canada
Your Mac's Specs
2011 27" iMac, 1TB(partitioned) SSD, 20GB, OS X 10.11.6 El Capitan
It clicks the same spot over and over, about every 20 seconds, or 40-45 seconds, I guess.



Hmmm…??? And that's something that's constructive for you…??? OK. I guess. :Blushing:





- Patrick
======
 
OP
B
Joined
May 22, 2017
Messages
6
Reaction score
0
Points
1
Modify your AppleScript to something like this
Code:
[COLOR=#333333]on idle
[/COLOR] [B] delay (random number from 20 to 25)[/B]
[COLOR=#333333]  tell application "System Events"[/COLOR]
[COLOR=#333333]    key code 87[/COLOR]
[COLOR=#333333]  end tell[/COLOR]
[COLOR=#333333]  return 20[/COLOR]
[COLOR=#333333]end idle[/COLOR]

I'm afraid I need more help. After I posted my original question and got an answer, everything had been going well.

Now, however, a wrinkle has appeared. After the click, the page suddenly drops to the bottom of the page. This is not good because now the cursor is no longer over the next button needing clicking. For clarification, it isn't the cursor that moves. It stays at the same spot. It is the page that scrolls to the bottom of the page as though sliding beneath the cursor.

Here is the script (slightly changed to repeat a little sooner):
on idle
delay (random number from 15 to 20)
tell application "System Events"
key code 87
end tell
return 10
end idle

How can I get the page to either not scroll after it completes the action or scroll back to the top after it takes a trip to the bottom? Cursor is behaving, it is the page that is testing my patience.

Edit: I am in Safari because that is where I can turn off all images and style so the buttons that need clicking will always appear in the same place. I can get the page to go back to the top using Command-Up. Would that help if it could be added to the script somehow? or is there a less clumsy way of doing it? I think it has to go either after the return 20 or at the beginning to reset the page?

I'm sorry my script seems useless. If anyone can direct me to a How-to on Apple Script, I promise to stop bugging you. *sheepish smile*
*leaves brownies as a bribe*
 
Last edited:

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,745
Reaction score
2,071
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Assuming that going to the top of the page with CMD+UP is always going to put the focus back where it needs to be, you can modify the script in the following way:
Code:
on idle
  delay (random number from 20 to 25)
  tell application "System Events"
    key code 87
[B]    delay 1
    key code 55 using { command down }[/B]
  end tell
  return 20
end idle

This will key in the number 5, wait for one second and then do the CMD+UP to take you back to the top of the page..

Don't worry about the usefulness or not of your script, it obviously serves a purpose to you and we are glad to help you along the way.
 
OP
B
Joined
May 22, 2017
Messages
6
Reaction score
0
Points
1
*grins*
Thanks.

Yes, doing it by hand has worked perfectly.
However, sometimes it takes several seconds to finish loading the page after the click (keying in the number 5) which is why return is so long. Would it be ok coding-wise to do it like this?

on idle
delay (random number from 20 to 25)
tell application "System Events"
key code 55 using { command down }
delay 1
key code 87
end tell
return 20
end idle

That way it would be back in place just before the click happens.

Of course, I could just go try it both ways, couldn't I?

Edit: I have tried it both ways and it still goes to the foot of the page and sits there. I am going to leave it as you wrote it, but try to play with the timing.

Edit: Still not working. Hmmmmm.
 
Last edited:

Slydude

Well-known member
Staff member
Moderator
Joined
Nov 15, 2009
Messages
17,596
Reaction score
1,072
Points
113
Location
North Louisiana, USA
Your Mac's Specs
M1 MacMini 16 GB - Ventura, iPhone 14 Pro Max, 2015 iMac 16 GB Monterey
@RazOrEdge I have an idea. I think it is possible and there are commands for this but can't look it up/test it for several days. As I understand it Bantymom has configured Safari in such a way that the area to be clicked is in the same place every time unless the page moves. Does AppleScript give you an accurate means to do the following?

1. Safari loads the first page as usual.
2. Bantymom positions the cursor and starts the script which does the following:
a. Script reads current location and stores coordinates in a variable
b. The click occurs.
c. Script moves cursor to the stored coordinates.
d. Click occurs
e. Lather, rinse, repeat
 
OP
B
Joined
May 22, 2017
Messages
6
Reaction score
0
Points
1
@RazOrEdge @Slydude

Update:
I have managed to get FF to work with this, so I've given up on Safari so the above problem is not longer an issue. I have removed these lines:

delay 1
key code 55 using { command down }

And it is running fine. Thank you so much for trying to find a fix for me.

Now I want to click in two different places. I pulled the edges of the window until they touched the bottom of the menu bar and all the edges, so that everything is always is the same place, and I found the location of the two things I want clicked.

My original concept for modification was this:

on idle
delay (random number from 1 to 5)
tell application "System Events"
(tell the mouse to move to specific coordinates here)
key code 87
delay 15
(tell the mouse to move to specific coordinates here)
key code 87
delay 15
end tell
return 10
end idle

but there just doesn't seem so be a simple way to tell the cursor where to move to. *sigh*

I thought I would be able to do this on my own. I mean, really, I'm not trying to do something very complicated. I've spent 2 days trying to figure out how to move the mouse to those two locations, but searches brought up only very complicated scripts, scripts nested inside other scripts, or scrips requiring a combination of scripting languages. Is it really so difficult to just move the mouse/cursor?

This is an example:
set x to 30
set y to 5
set l to 50 -- click same location 50 times
do shell script "
/usr/bin/python <<END
import sys
import time
from Quartz.CoreGraphics import *
def mouseEvent(type, posx, posy):
theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
CGEventPost(kCGHIDEventTap, theEvent)
def mousemove(posx,posy):
mouseEvent(kCGEventMouseMoved, posx,posy);
def mouseclick(posx,posy):
mouseEvent(kCGEventLeftMouseDown, posx,posy);
mouseEvent(kCGEventLeftMouseUp, posx,posy);
ourEvent = CGEventCreate(None);
currentpos=CGEventGetLocation(ourEvent); # Save current mouse position
for x in range(0, " & l & "):
mouseclick(" & x & "," & y & ");
mousemove(int(currentpos.x),int(currentpos.y)); # Restore mouse position
END"

Below is the most simple one I found:

tell application "Safari"
activate
end tell
repeat with i from 1 to 10
delay 5
tell application "System Events"
tell process "Safari"
click at {46, 239}
end tell
end tell
end repeat

Additionally, all of my experiments have been refused by Accessibility, which I had to use to run the original script. I tried to add it to the permissions, and it ignored me. (And now I can't seem to find that window) I thought I would be very clever and just edit my ideas into the script that is already there, but anything involving locations gives me a notice that it isn't allowed or some such thing.


Help? It is really so complicated. I am just looking for a simple way to do a simple thing.
Do I need Applescript Toolbox for this?
 
Last edited:

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top