1

我想使用 AppleScript 之类的东西为键盘快捷键分配右键单击上下文。

例如:

如果我右键单击 Dropbox 中的文件夹,它会给我一个“共享 Dropbox 链接”菜单。是否可以在不使用鼠标的情况下访问它?

4

2 回答 2

0

您可以使用下面的脚本来访问上下文菜单,您将需要 MouseLocation 和通过 Google 找到的 cliclick。

您可能需要稍微编辑一下(并调整 MouseLocation 和 cliclick 的硬编码路径),但这应该没问题,我认为您可以使用系统事件和键代码命令来导航上下文菜单。

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

编辑:

我不知道您再也无法通过 Google 找到 MouseLocation,对此我深表歉意如果您在编译此线程 ( http://www.macscripter.net/viewtopic.php ?id=33468),那么我建议您使用此处找到的 MouseTool :( http://www.hamsoftengineering.com/codeSharing/MouseTools/MouseTools.html),然后您需要更改脚本的前四行类似于:

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

(您必须调整 MouseTools 的路径以及 cliclick。)

于 2013-07-14T19:24:20.437 回答
0

根据这篇文章,似乎可以在系统内使用 Universal Access 执行此操作。

于 2013-07-16T16:13:14.723 回答