How do you write the command to carry out a double click with a mouse at a specific location in AppleScript?
Double click in AppleScript
applescriptclickscript
Related Solutions
There are tons of command line utilities to do this... and I'd reckon that going this route's your best bet... One benefit? is that these solutions should work, irrespective of whether or not "mouse keys" are on, right? One of my particular faves is cliclick
Cliclick” is short for "Command-Line Interface Click". > It is a a tiny shell / Terminal application that will emulate mouse clicks or series of mouse clicks (including doubleclicks and control-clicks) at arbitrary screen coordinates.
Hence, it is a tool for automating / scripting things that cannot otherwise be scripted (for instance, using AppleScript). Other than GUI Scripting, it does not require "Access for assistive devices" to be activated in the System Preferences.
Usage:
$ cliclick c m
will "control-click" the current mouse location, but you can also specify the coordinates, shift-click, double-click, etc. It can also return the coordinates of the mouse with a -q
argument, and return the mouse to the original location (when specifying coordinates) with the -r
argument.
In your case.. I guess you'd just...
do shell script "cliclick c m"
from inside your AppleScript / Workflow / whatever...
There's a GREAT post on this subject on MacWorld's site (née Mac OS X Hints) - that I've gleaned lots of good info from, over the years. If you don't care for my answer you will surely find a solution you DO like, there... there's hacks to make everyone smile - from an Automator freak = to a grumpy C diehard.
Update:
There do seem to be some ways - to "do it" in AppleScript.. but they all seem to require knowing where your mouse is... which i assume you don't. So in an embarrassingly nerdy play for some rep... I wrote this..
do shell script "python -c 'import sys, time; from Quartz.CoreGraphics import *;
def mouseEvent(type, posx, posy):
theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft);
CGEventPost(kCGHIDEventTap, theEvent);
def mouseclickdn(posx,posy):
mouseEvent(kCGEventLeftMouseDown, posx,posy);
def mouseclickup(posx,posy):
mouseEvent(kCGEventLeftMouseUp, posx,posy);
ourEvent = CGEventCreate(None);
currentpos = CGEventGetLocation(ourEvent);
print currentpos[0];
print currentpos[1];
mouseclickdn(currentpos.x, currentpos.y);
mouseclickup(currentpos.x, currentpos.y)'
"
What the hell is it?
- AppleScript calls 'do shell script'.
- Which then calls Python - with a command line argument (
-c
) = that's been escaped and cajoled = to cooperate with A/S. - Python then "imports" CoreGraphics/Quartz, etc.
- And defines some Cocoa-API/PyObjC methods for "dealing with" the mouse.
- Python "figures out" where the mouse is.
- And clicks! (down, then up)
- As a bonus, it returns the coordinates of the mouse, 'if you were interested_.
Works 100% and isn't even THAT slow. Hope you like it!
Edit:
Here is the BASH one-liner, for purists / A/S haters.
echo -e "import sys, time; from Quartz.CoreGraphics import *\ndef mouseEvent(type, posx, posy): theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft); CGEventPost(kCGHIDEventTap, theEvent);\ndef mouseclickdn(posx,posy): mouseEvent(kCGEventLeftMouseDown, posx,posy);\ndef mouseclickup(posx,posy): mouseEvent(kCGEventLeftMouseUp, posx,posy);\nourEvent = CGEventCreate(None); currentpos = CGEventGetLocation(ourEvent); print currentpos[0]; print currentpos[1]; mouseclickdn(currentpos.x, currentpos.y);\nmouseclickup(currentpos.x, currentpos.y);" | python
You can rule out SteerMouse, I just connected a second mouse and there is only one setting for double-click delay shown. Based on that I'm doubtful of USB Overdrive's claim: "The USB Overdrive can easily handle several USB devices at once and can assign different settings to each one." - but it's probably worth a look!
I think ControllerMate could do it if the developer felt like it - it's a way more configurable approach and is flexible enough to build complex control schemes for HOTAS game controllers. You should register your interest in being able to control the Magic Trackpad with a quick email. I don't know for sure that ControllerMate can't do what you want, it all depends on whether its building block approach sees a "Source" for each mouse-like device or whether it just uses the kernel's mouse driver output and sees an aggregate of control input for the two devices. There is a time-limited trial available.
Related Question
- Using Javascript | Applescript to click button in Safari
- MacOS – How to disable double-click to launch iTunes and play song in OS X Mavericks
- How to make the mouse click at current location using AppleScript
- MacOS – AppleScript: How to double-click & right-click at cursor location
- MacOS – AppleScript to set clock
Best Answer
You can use AppleScript to click twice using
click at
and a delay.