1

I'd like to assign a right-click context to a keyboard shortcut using something like an AppleScript.

For example:

If I right click a folder in Dropbox it gives me a "Share Dropbox Link" menu. Is it possible to access this without using the mouse?

SparrwHawk
  • 13,581
  • 22
  • 61
  • 91

2 Answers2

0

You can use my script below for accessing the context menu, you'll need both MouseLocation, and cliclick that you'll find via Google.

You may want to edit it a little (and adjust the hardcoded paths to both MouseLocation, and cliclick), but it should really be no problem, I think you can use System Events and key code commands to navigate the context menu.

set mouseLoc to (do shell script "/usr/local/opt/MouseLocation")
set {astid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}
tell mouseLoc to set {mouseX, mouseY} to {it's text item 1, it's text item 2}
set {mouseX, mouseY} to {(mouseX as integer), 1200 - (mouseY as integer)}

tell application "System Events"
    set frontProcessName to name of every process whose frontmost is true
    --  tell a to set aa to (get its name)
    set wnCount to count of windows of process named frontProcessName
    if wnCount > 0 then
        tell window 1 of process named frontProcessName
            set wnPos to its position
            set wnsize to its size
        end tell
        set {wnX, wnY, wnWidth, wnHeight} to {item 1 of wnPos, item 2 of wnPos, item 1 of wnsize, item 2 of wnsize}

        set {leftBound, RightBound, upperBound, lowerBound} to {wnX + 1, (wnX + wnWidth - 21), wnY + 50, (wnY + wnHeight - 51)}
        if mouseX ≥ leftBound and mouseX ≤ RightBound then
        else if mouseX < leftBound then
            set mouseX to leftBound
            log "a"
        else
            set mouseX to RightBound
            log "b"
        end if

        if mouseY ≥ upperBound and mouseY ≤ lowerBound then
        else if mouseY < upperBound then
            set mouseY to upperBound
            log "c"
        else
            set mouseY to lowerBound
            log "d"
        end if

    end if
end tell
set mouseLoc to "c" & mouseX & " " & mouseY
do shell script "/usr/local/opt/cliclick " & mouseLoc
set AppleScript's text item delimiters to astid

Edit:

I didn't know that you couldn't find MouseLocation via Google anymore, I am sorry about that If you have problems compiling the code found in post # 3 in this thread (http://www.macscripter.net/viewtopic.php?id=33468), then I recommend you use the MouseTool found here :(http://www.hamsoftengineering.com/codeSharing/MouseTools/MouseTools.html) instead, you would then need to change the first four lines of the script to something like:

set mouseLoc to (do shell script "MouseTools -location")
set {astid, AppleScript's text item delimiters} to {AppleScript's text item delimiters,    return}
tell mouseLoc to set {mouseX, mouseY} to {it's text item 1, it's text item 2}
set {mouseX, mouseY} to {(mouseX as integer),(mouseY as integer)}

(You'll have to adjust the path to MouseTools as well as to cliclick.)

McUsr
  • 1,400
  • 13
  • 10
  • Hey thanks for answering; can you link to the MouseLocation tool? I've tried various Google searches such as MouseLocation shell script but Google returns nothing useful – SparrwHawk Jul 16 '13 at 20:28
  • Hello. I am sorry about MouseLocation not being found by google. I have provided a better alternative tool in my post. HTH – McUsr Jul 16 '13 at 23:53
  • Hi McUser, thanks for your help. I'm getting this error: Can’t make " MouseTools" into type integer. I would paste my code in here, but it's too long; but I have followed your instructions. – SparrwHawk Jul 17 '13 at 22:02
  • Hello. Try executing this line in a separate script After you have prepended MouseTools with the path you use for MouseTools: log "" & (do shell script "which MouseTools") Then. Look into the log in Applescript Editor. Either your path is wrong, or missing. – McUsr Jul 18 '13 at 13:51
  • Hi, the error I'm getting is: error "Can’t make \" MouseTools\" into type integer." number -1700 from " MouseTools" to integer – SparrwHawk Jul 20 '13 at 21:42
  • Hello. I'm sorry you couldn't make it work. I am sure that if you add the path to where you installed Mousetools, to the second block of code, then you should have been able to make it work. – McUsr Jul 26 '13 at 14:04
0

According to this post, it seems to be possible to do this within the system, using Universal Access.

Community
  • 1
  • 1
Darrick Herwehe
  • 3,553
  • 1
  • 21
  • 30