是否可以使用AppleScript访问右键单击上下文?

时间:2013-07-10 19:11:08

标签: shell scripting applescript keyboard-shortcuts dropbox

我想使用像AppleScript这样的东西为键盘快捷键指定一个右键单击上下文。

例如:

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

2 个答案:

答案 0 :(得分:0)

您可以使用我下面的脚本访问上下文菜单,您需要同时使用MouseLocation和cliclick,这些都可以通过Google找到。

您可能想要稍微编辑它(并将硬编码路径调整为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了,我很抱歉 如果您在编译此帖子中的帖子#3中找到的代码时出现问题(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。)

答案 1 :(得分:0)

根据this post,似乎可以使用Universal Access在系统内执行此操作。