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

Automator auto click

Hi
I'm trying to make a very simple script that will click an on-screen (Safari window) button repeatedly until I tell it to stop. I can place the cursor on the button at the beginning so the script doesn't even have to find it. I have tried using 'watch me do' and then 'loop' but although this seems like a good solution in reality it throws up a general error and stops running and I can't work out why.

Any pointers?
A

Quad core, Mac OS X (10.5.5)

Posted on Jul 24, 2010 4:10 AM

Reply
Question marked as Best reply

Posted on Jul 28, 2010 5:01 AM

If your keyboard has a numeric keypad, you might try this...

1) In System Preferences > Universal Access > Mouse, turn on Mouse Keys and check "Enable access for assistive devices."

2) Copy the code below and paste it into your AppleScript Script Editor (Applications > Applescript > Script Editor.app). From the Editor's File menu select Save As > File Format: Application, and make sure to check "Stay Open" under Options.

*on idle*
*tell application "System Events"*
*key code 87 -- no. 5 on numeric keypad*
*end tell*
*return 10 -- clicks every 10 seconds; adjust to suit*
*end idle*

Launch the script and then move your mouse pointer over the desired button. A mouse click will occur every 10 seconds thereafter (to adjust the interval, edit the *return 10* command appropriately). To quit the script at any time, click on its docked icon and select Quit from the menu. Hope this helps.
3 replies
Question marked as Best reply

Jul 28, 2010 5:01 AM in response to Vertigo13

If your keyboard has a numeric keypad, you might try this...

1) In System Preferences > Universal Access > Mouse, turn on Mouse Keys and check "Enable access for assistive devices."

2) Copy the code below and paste it into your AppleScript Script Editor (Applications > Applescript > Script Editor.app). From the Editor's File menu select Save As > File Format: Application, and make sure to check "Stay Open" under Options.

*on idle*
*tell application "System Events"*
*key code 87 -- no. 5 on numeric keypad*
*end tell*
*return 10 -- clicks every 10 seconds; adjust to suit*
*end idle*

Launch the script and then move your mouse pointer over the desired button. A mouse click will occur every 10 seconds thereafter (to adjust the interval, edit the *return 10* command appropriately). To quit the script at any time, click on its docked icon and select Quit from the menu. Hope this helps.

Apr 25, 2017 9:04 AM in response to Andrew99

**Use caution when writing Apple Scripts**


They can be helpful, or harmful, like any tool.


I used this to simulate clicking on the screen for an idle game played in a website using Safari. It does work even on a MacBook with no numeric keypad. The script emulates the key code that would correspond to the numeric keypad '5', even if there is no physical key. You can use the keyboard shortcut 'alt/option' 5 times to turn Mouse Keys on or off. When off, key code 87 triggers the unicode for the number five. When on, key code 87 triggers a mouse button press/release cycle.


Yay, it worked!

Now, instead of one click per second how about 10, or 100 clicks per second... that idle game won't know what hit it!

...but wait

There's that little voice again saying 'hold on now'...


*** CAUTION ***

This became uncontrollable for me. My computer was clicking on whatever the mouse was over once per second (I changed the time in the above script from 10 to 1). Turning off Mouse Keys helped. Now instead of clicking, my computer was typing the number '5' repeatedly. Trouble is I couldn't stop it, or log off, or change user. Upon hard power down and restart the script was still there typing away.

While waiting on hold for Apple tech support I figured out I could Quit the Apple Script. If you follow the above instructions the script is an application. It is running in the dock. If you turn off Mouse Keys (alt 5 times) you at least have control of your mouse even though the computer is typing the number '5' repeatedly. Look in the dock for the script icon and quit it by one of two means:

- command / right click then quit

- select icon to make it the active application, command Q to quit


Happy scripting, and please don't be me. Read up on Apple's website (and other's are helpful) to learn a bit about Apple Scripts before you blindly cut and paste!

Automator auto click

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