使用 AppleScript 和 Automator 在带有键盘的 Mac 上显示上下文菜单

2024-04-24

我正在尝试找到一种方法,在使用 Yosemite 的 Mac 上的 Finder 中调出上下文菜单without触摸鼠标/触摸板。

a context menu
A context menu.

经过对此问题的广泛研究,唯一可能的途径似乎是使用 AppleScript 和 Automator,并为其分配键盘快捷键。

下面的 AppleScript 是在 stackoverflow 上找到的,如果我在 Automator 中运行它,它会在桌面上的一个文件(不是当前选定的文件)上显示上下文菜单。

tell application "System Events"
    tell process "Finder"
        set target_index to 1
        set target to image target_index of group 1 of scroll area 1
        tell target to perform action "AXShowMenu"
    end tell
end tell


Automator screenshot

但我在使用键盘快捷键时遇到了麻烦。
另外,我需要确保它带来当前所选文件的菜单。

有人可以提供一些关于如何做到这一点的见解吗?


您可以在此处阅读以下脚本:MacScripter / 右键单击 http://www.macscripter.net/viewtopic.php?pid=178866#p178866

 # Copyright © 2012 - 2015 McUsr
 run showRightClickMenu
 script showRightClickMenu
    on run
        set mouseLoc to (do shell script "~/opt/bin/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), 1200 - (mouseY as integer)}

        tell application id "sevs"
            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
                else
                    set mouseX to RightBound
                end if

                if mouseY ≥ upperBound and mouseY ≤ lowerBound then
                else if mouseY < upperBound then
                    set mouseY to upperBound
                else
                    set mouseY to lowerBound
                end if

            end if
        end tell
        set mouseLoc to "c" & mouseX & " " & mouseY
        do shell script "~/opt/bin/cliclick " & mouseLoc
        set AppleScript's text item delimiters to astid
    end run
 end script
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 AppleScript 和 Automator 在带有键盘的 Mac 上显示上下文菜单 的相关文章

随机推荐