4

How do you write the command to carry out a double click with a mouse at a specific location in AppleScript?

grg
  • 201,078

2 Answers2

3

You can use AppleScript to click twice using click at and a delay.

tell application "System Events"
  click at {10, 10}
  delay 0.1
  click at {10, 10}
end tell
grg
  • 201,078
  • What units are the co-ordinates in? Pixels? – Ian C. Jun 07 '14 at 16:14
  • 1
    @Ian The dictionary says "in global coordinates"; not quite sure what this translates to, as {10, 10} is definitely not 10 pixels in on my retina display, but may be on a non-retina display (don't have one to test on)? – grg Jun 07 '14 at 16:17
  • 1
    Testing this (I'm on rMBP as well) results in the following: error "System Events got an error: Can’t make {10, 10} into type list." number -1700 from {10, 10} to list – njboot Jun 08 '14 at 00:56
  • Thanks for your help. I want to open an application called UVIWorkstation and you have to double click on an input window to open the browser. I can find the coordinate position in pixels and I want to double click on this position. The code tell application "UVIWorkstation" click at {455, 149} delay 0.1 click at {455, 149} end tell produces the error – Ray d'Inverno Jun 09 '14 at 15:06
  • Thanks for your help. I want to open an application called UVIWorkstation and you have to double click on an input window to open the browser. I can find the coordinate position in pixels and I want to double click on this position. The code

    tell application "UVIWorkstation" click at {455, 149} delay 0.1 click at {455, 149} end tell

    leads to error "UVIWorkstation got an error: Can’t continue click." number -1708

    I am having real trouble using the Ask Different editor. Every time I hit return it throws me out. Ray

    – Ray d'Inverno Jun 09 '14 at 15:16
  • @Ray You're telling UVIWorkstation but you need to tell System Events to click. Don't modify anything in the script but the position (and the delay if necessary). – grg Jun 09 '14 at 18:23
  • Silly me - sorry. I have tried your double click program just to open a text document on the desktop but nothing happens. I have tried varying the delay, but still nothing.

    Are you abel to place the left hand corner of one finder window on the desktop in the middle of the icon for an rtf file, then find its position with

    tell application "Finder" to get the position of the front Finder window

    which gives you coordinates (x,y) and then open it with your double click program.

    Thanks for your help. If I can get this working then I should be able to do everything else I need.

    Ray

    – Ray d'Inverno Jun 11 '14 at 14:20
  • 1
    There was a bug with click at on Mavericks. It works again on Yosemite. – Matthieu Riegler Oct 17 '14 at 17:03
0

I'm afraid, double clicks no longer work if you run "El capitan"...

System Events' sdef file says "click at"s must be sent to a process object. This certainly includes buttons, menus, their items & some others, but not even (e.g.) objects visible on your desktop ...

As clicks on UI elements usually demand only one click, double clicks seem to be obsolete in AppleScript (for now).

clemsam lang
  • 1,132