4

So I've been trying to make a program using AppleScript, but there's one thing that's been teasing me for some time now - How do I make the mouse click at current location without using Mouse Keys?

Also, is it possible to simulate a long click (that means I set the length of it)?

7

You can simulate a mouse click with AppleScript code like this:

tell application "System Events"
  click at {123,456}
end tell

This means to simulate a click of the mouse at coordinate (123,456).

To click at the current location you'll need to first find the current location of the mouse pointer, if you don't know it already. This is not easily done with AppleScript itself, so a neat way is to use the third party tool "MouseTools".

You can download it for free here.

On the download webpage you'll find an AppleScript example for getting the current mouse coordinates.

  • is it capable of long clicking? – Prokop Hanzl Dec 30 '16 at 12:16
  • also, you said it isn't easily done, does that mean it is possible w/out MouseTools? it'd be awesome if it worked on other computers which don't have MT downloaded, else I'd have to bundle it w/ my program – Prokop Hanzl Dec 30 '16 at 12:19
  • and one more thing - you seem smart about AppleScript - would you please check out my unanswered questions? I have a feeling you might know the answers - thanks – Prokop Hanzl Dec 30 '16 at 12:22
  • @ProkopHanzl It is both easily done and possible yes. I said it was not easy WITHOUT MouseTools (or similar), but with MouseTools it is very easy. Without MouseTools you would have to find your own solution. – jksoegaard Dec 30 '16 at 13:07
  • @ProkopHanzl Regarding your other, non-related questions - I have no real experience with AppleScript, so you'll have to look elsewhere for answers. – jksoegaard Dec 30 '16 at 13:08
1

Wouldn't it be much more convenient to be able to do everything right in script editor?

You should definitely grab the AppleScript toolbox. It has scripting commands to get your mouse location and mouse clicking.

AppleScript Toolbox is a scripting addition/AppleScript-plugin (a.k.a. “OSAX”) providing commands not available in regular AppleScript.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .