How to make the mouse click at current location using AppleScript

applescript

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)?

Best Answer

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.