Apple Intelligence now features Image Playground, Genmoji, Writing Tools enhancements, seamless support for ChatGPT, and visual intelligence.

Apple Intelligence has also begun language expansion with localized English support for Australia, Canada, Ireland, New Zealand, South Africa, and the U.K. Learn more >

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.

How do you make an applescript mouse clicker?

I need an applescript script that can click on certain points over and over again. I'm sorry, but i'm a complete noob at any scripting, so you migt have to hold my hand and walk me through it.

MacBook Pro

Posted on Feb 3, 2012 6:29 PM

Reply

Posted on Apr 10, 2014 2:23 AM

When I run this code snippet I see the following error message


System Events got an error: Can’t make {699, 242} into type list.



Trying to send a click to Chrome.

21 replies

Feb 7, 2012 8:12 PM in response to Smiles2212

In this context System Events is used to script an application's user interface, so "X" would be the application that you tell to click the mouse - change it as needed (the application also needs to be activated to bring it to the front).


It might help to know exactly what you are wanting to do - trying to do something like making a hack for World of Warcraft isn't quite what AppleScript is good at.

Feb 3, 2012 9:11 PM in response to red_menace

Actually, Red, that's not true. the following code will supposedly click at x=100 y=200 in a given app:


tell application "System Events"

tell process "X"

click at {100, 200}

end tell

end tell


I've never actually used this feature - it says it will click at {x,y} in global (assumedly desktop) coordinates, but it might take some poking around to to get it clicking in the right place.

Apr 10, 2014 5:59 AM in response to Smiles2212

You can use python wrapped in Applescript:


set x to 30

set y to 5


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

mouseclick(" & x & "," & y & ");

mousemove(int(currentpos.x),int(currentpos.y)); # Restore mouse position

END"

Apr 10, 2014 7:07 AM in response to Tony T1

This will the same location 50 times:


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"

Aug 31, 2014 11:24 AM in response to Tony T1

Is there a way to modify this script to terminate early when a particular key is pressed? I don't really care if the key is option, fn1, esc, or Z, so long as it works. =p


I tried to find a solution for this via Google, but the closest answer that I found was https://docs.python.org/2/faq/library.html#how-do-i-get-a-single-keypress-at-a-t ime, which I couldn't figure out how to modify for my purposes. (since I have 0 experience with coding, except for a little dabbling in XML)

Jun 11, 2015 4:44 PM in response to Max Curious

If you download Carsten BlĂĽm's Cliclick @ https://www.bluem.net/en/mac/cliclick/ and install it into /usr/local/bin you can run this command in Script Editor to left click the current position of the mouse cursor:

do shell script "usr/local/bin/cliclick c:."


The "c" is the command identifier for clicking, the "." or period is the command argument, and the ":" or colon separates the two. The following command is equivalent and uses relative zero values instead:

do shell script "usr/local/bin/cliclick c:+0,+0"


Since Cliclick is a command-line tool, you can use this command in Terminal to do the same thing:

cliclick c:+0,+0


Another tool you can use is PyMouse, now a part of PyUserInput. You can download it from GitHub @ https://github.com/SavinaRoja/PyUserInput. Install instructions @ https://github.com/SavinaRoja/PyUserInput/wiki/Installation. To use in Script Editor, you can use this command to left click the current position of the mouse cursor:

do shell script "

/usr/bin/python <<END

from pymouse import PyMouse

m = PyMouse()

pos = m.position()

m.click(pos[0], pos[1])

END"

Sep 13, 2015 8:19 AM in response to Roote

This is easy to implement and understand


on ChromeButtonsEasy(TheTargetURL, TheTargetButtonId)

(*below to be duplicated and placed before "my ChromeButtonsEasy(TheTargetURL, TheTargetButtonId)"*)

(*set TheTargetURL to "Blank_1"

set TheTargetButtonId to "Blank_2"*)


(* Replace Blank_1 with url of your target page by copeying the address bar

Replace Blank_2 by using right click in chrome on the button and copying snippett after id *)

tell application "Google Chrome"

if not (existswindow 1) then reopen


activate

tell window 1 to tell active tab

set its URL to TheTargetURL


delay 3


executejavascript "document.getElementById(" & quoted form of TheTargetButtonId & ").childNodes[0].click()" --find the id by using inspect element

end tell

end tell

end ChromeButtonsEasy

Aug 17, 2016 7:55 PM in response to red_menace

Hello - hoping you can help. I'm using this Applescript in an attempt to click at a specific coordinate in FileMaker Pro, but very little experience here and it's not working. It will bring up the application, but not click at the coordinates. Any suggestions? I'm using FM 9 and El Capitan OS.


tell application "System Events"

tell process "FileMaker Pro"

click at {308, 355}

end tell

end tell



Thank you.

Oct 1, 2016 7:57 AM in response to Smiles2212

I wanted to do the same thing and came across this discussion thread 🙂

Thank you everyone who inspired me:


The applescript "click at" method always returns "missing value" error for me. I have read somewhere that this is due to new version of OS X. I'm using OS X 10.10.5 at the moment.


I wanted an applescript to open Safari and then repeatedly click on certain point of the screen, and then scroll down.

I found that Cliclick (you can download with the link in above) is easier to use for me, and it can also do the "arrow-down" keypress that scroll down the screen which is what i needed.



I finally did an applescript like this:



tell application "Safari" to activate


delay 5


do shell script "


PATH=$PATH:/Applications/cliclick/


posY=725


for i in {1..20}


do


echo \"$i times... Y is $posY \"


cliclick c:581,$posY w:500 m:+295,+0 c:. w:500 m:+295,+0 c:. w:2000


cliclick kp:arrow-down w:500 kp:arrow-down w:500 kp:arrow-down w:500 kp:arrow-down w:500 kp:arrow-down w:500


cliclick kp:arrow-down w:500 kp:arrow-down w:500 kp:arrow-down w:500 kp:arrow-down w:500 kp:arrow-down w:2000


posY=$(($posY-1))

"


done

"


"

Nov 1, 2016 1:55 PM in response to thankgodforapple

dowload https://github.com/BlueM/cliclick

unzip cliclick-master.zip

in a Terminal

cd /Users/yourname/Downloads/cliclick-master

make

now you have in /Users/yourname/Downloads/cliclick-master/

cliclick , command tool for using a mouse in applescript with do shell script

copy cliclick in /usr/local/bin folder

in a Terminal

cp -f /Users/yourname/Downloads/cliclick-master/cliclick /usr/local/bin/

in applescript for example

do shell script "/usr/local/bin/cliclick " & quoted form of "c:12,34"

will click at the point with x coordinate

12 and y coordinate 34.

in a Terminal for LIST OF COMMANDS

cliclick -h



other way in Applescript


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

"

How do you make an applescript mouse clicker?

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