-
All replies
-
Helpful answers
-
Feb 3, 2012 6:40 PM in response to Smiles2212by red_menace,If you are talking about some random point on the screen, AppleScript desn't have anything to do that - take a look at MouseTools.
-
Feb 3, 2012 9:11 PM in response to red_menaceby twtwtw,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.
-
Feb 3, 2012 11:13 PM in response to twtwtwby red_menace,You are correct in that the click will send the {x,y} location to a process object (UI element), but I haven't had much luck using System Events to just click at some random location (especially if you want to use something like a right-click) - hence my qualifier.
-
Feb 4, 2012 12:03 AM in response to red_menaceby twtwtw,Well, the OP hasn't really clarified what it is he wants clicked, so we'll have to wait for details.
-
Feb 7, 2012 6:38 PM in response to twtwtwby Smiles2212,if i use this script, I get the error "System Events got an error: Can’t get process "X". I'm a complete noob at applescript, so i'm sorry if i'm being stupid to you.
-
Feb 7, 2012 8:12 PM in response to Smiles2212by red_menace,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 8, 2012 4:09 AM in response to red_menaceby Smiles2212,lol. i don't play world of warcraft, but thank you for the info
-
by Hate when you ask for personal details,Apr 10, 2014 2:23 AM in response to red_menace
Hate when you ask for personal details
Apr 10, 2014 2:23 AM
in response to red_menace
Level 1 (0 points)
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.
-
Apr 10, 2014 5:59 AM in response to Smiles2212by Tony T1,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 T1by 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"
-
Jun 16, 2014 1:12 PM in response to Tony T1by richardfromcascais weymouth,thankyou for the script it works great! If you composed it well done.
-
by Tony T1,Jun 16, 2014 3:20 PM in response to richardfromcascais weymouth
Tony T1
Jun 16, 2014 3:20 PM
in response to richardfromcascais weymouth
Level 6 (9,232 points)
Mac OS Xrichardfromcascais weymouth wrote:
thankyou for the script it works great! If you composed it well done.
Credit goes to: http://www.geekorgy.com/index.php/2010/06/python-mouse-click-and-move-mouse-in-a pple-mac-osx-snow-leopard-10-6-x/
-
Aug 31, 2014 11:24 AM in response to Tony T1by WordsInTheDark,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)
-
May 18, 2015 2:16 PM in response to Smiles2212by Max Curious,I have the same almost exact question..except I need to perform a mouse click on a field in Filemaker Pro. The coordinates could be anywhere at anytime...but it would be the field currently highlighted.
Why is it so hard to say on Mac OS...just perform a mouse click now...and ignore coordinates?