3

I want to be able to double-left-click, then immediately right-click using AppleScript.

The location of the click is wherever my cursor is located at the time that the AppleScript is triggered.

The AppleScript will be triggered by FastScripts via keyboard shortcut. I would like the script to work across all applications.

I installed cliclick. When I type cliclick -h into Terminal, I see that it can double-click, but there is no mention of the right-click.

4

Since you already know how to double-click with cliclick, my answer focuses on the right-click and traditionally on a Mac one used to preform a right-click via control-click, and as such you need to do the same thing when using cliclick.

As an example, using cliclick in Terminal, it will attempt to open the manual page for cliclick. I said attempt to open because cliclick doesn't have a manual page but will use the command line to preform some actions that will control-click (right-click) to bring up the context menu, move the mouse to click Open man page as I've selected cliclick in the command line before pressing enter to execute the command line.

The image below shows the command line twice just so you can plainly see the full command line in the first line as part is obfuscated in the second line that's preforming the actual clicking on the
Open man page from the context menu.

enter image description here

The image below is what appeared and was clicked when the cliclick command line was executed.

enter image description here

The image below is cropped but is presented to show it tried to open the manual page for cliclick.

enter image description here

I do not use FastScripts, however the example command should help you to understand what to pass cliclick to do whatever it is you're trying to do.

The cliclick command line explained:

  • cliclick kd:ctrl c:+0,+0 ku:ctrl m:+5,+5 c:+0,+0 - Full command line.
  • cliclick - The binary executable.
  • kd:ctrl - Press the control key down.
  • c:+0,+0 - Click relative to where the mouse is presently.
  • ku:ctrl - Let the control key up.
  • m:+5,+5 - Move the mouse five pixels on the x,y axis relative to where the mouse is presently.
  • c:+0,+0 - Click relative to where the mouse is presently.

  • Note: The full command line above can also be expressed as,
    cliclick kd:ctrl c:. ku:ctrl m:+5,+5 c:. since a . can be used in place of x,y axis coordinates e.g., +0,+0 for the relative position of the mouse. I personally prefer to use the former over the latter, however both forms work.

As you can see in the first image that cliclick was selected and the mouse, show as a text cursor, is right over the selection, then when the cliclick commands were executed, it opened the man page Terminal window for it, although these isn't one. However, it shows that a right-click was made and the mouse moved to the entry on the context-menu and clicked.

In AppleScript the above command line would be wrapped in a do shell script command as shown below:

do shell script "/usr/local/bin/cliclick kd:ctrl c:+0,+0 ku:ctrl m:+5,+5 c:+0,+0"

Note: Use the fully qualified pathname to the cliclick binary executable if it's in a location that is not in the PATH passed to AppleScript.

  • Thank you for the detailed answer. I almost have the perfect script. I am using this script to highlight text and then right-click the text. Is there a way for the text to remain highlighted/selected after the right-click (just like it would normally)? This is my full code: do shell script "/usr/local/bin/cliclick dc:+0,+0 kd:ctrl c:+0,+0". My code un-selects the selected text when it right-clicks. – rubik's sphere Mar 15 '17 at 19:27
  • @rubik's sphere, I believe my answer as written addresses the real question asked, that being how to right-click with cliclick and this is not the place to debug what you're trying to do with it. I'd suggest starting another question while providing all info necessary to replicate any issue(s) you're having. That said, your cliclick command, as written, is doing exactly what it's supposed to be doing, even if the results are not right. Why are you even doing a right-click at the point you are as all it does is bring a the context menu. You need to do something else afterwards too. – user3439894 Mar 15 '17 at 19:56
  • @rubik's sphere, Also note you may need to use the w:ms commands appropriately within the cliclick command line as necessary. – user3439894 Mar 15 '17 at 19:57
  • @rubik's sphere, Sorry I never saw your edit, the paragraph starting with "To elaborate on the context", until now however I stand by what I've already said. BTW That edit, made more then an hour after I answered the original question as originally written, changes the overall scope of the question where my original answer covered what you didn't know to what I'd consider to be a totally different question after the fact. So lets separate the issue with a new and separate question. – user3439894 Mar 15 '17 at 20:15
0

There's now a simple solution: an rclick command was added to cliclick in version 4.0, released on 2018-03-24. Details at cliclick version history.

You must log in to answer this question.

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