How to script an auto clicking program in AppleScript with multiple mouse locations

I have no experience in scripting but I want to make an auto clicking program where it click in 3 different locations on the screen in a sequence. Is this possible with to do with apple scripts? I am using a MacBook Pro (15-inch, Mid 2012) OSX Yosemite.

MacBook Pro

Posted on Dec 8, 2014 4:20 AM

Reply
16 replies

Dec 8, 2014 6:50 AM in response to YuuTang

This is a python script wrapped in an Applescript.

See the 3 mouseclick(x, y); commands near the end that clicks 3 positions on the menu bar.


do shell script "
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);
time.sleep(2);
ourEvent = CGEventCreate(None);
currentpos=CGEventGetLocation(ourEvent); # Save current mouse position
mouseclick(5, 10);
time.sleep(2);
mouseclick(200, 10);
time.sleep(2);
mouseclick(300, 10);
time.sleep(2);
mousemove(int(currentpos.x),int(currentpos.y)); # Restore mouse position
END
"

Dec 8, 2014 7:04 PM in response to Tony T1

I am getting an error message once the program finishes running:


error "Traceback (most recent call last):

File \"<stdin>\", line 23, in <module>

NameError: name 'END' is not defined" number 1

Also, if I wanted to insert a key being pressed how would i do it? And how do I loop this script? Sorry for all the questions, I am a total newbie at this. Thank you!

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to script an auto clicking program in AppleScript with multiple mouse locations

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