问题描述
我正在尝试找到一种方法来在带有 Yosemite 的 Mac 上的 Finder 中调出上下文菜单而无需触摸鼠标/触摸板.
I am trying to find a way to bring up the context menu in Finder on a Mac with Yosemite without touching the mouse/touchpad.
上下文菜单.
经过对这个问题的广泛研究,唯一可能的途径似乎是将 AppleScript 与 Automator 一起使用,并为其分配键盘快捷键.
After extensive research on this issue, the only possible route seems to be using AppleScript with Automator, and assign keyboard shortcut to it.
下面的 AppleScript 是在 stackoverflow 上找到的,如果我在 Automator 中运行它,它会在桌面上的一个文件(不是当前选择的文件)上调出上下文菜单.
The AppleScript below was found on stackoverflow, if I run it inside the Automator, it would bring up the context menu on one of the files on the desktop (not the file currently selected.)
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 屏幕截图
但是我无法使用键盘快捷键使用它.
此外,我还需要确保它会显示当前所选文件的菜单.
But I am having trouble getting it to work with keyboard shortcut.
Also I will need to make sure that it brings the menu for the currently selected file.
有人可以提供一些有关如何做到这一点的见解吗?
Can someone provide some insight about how this can be done?
推荐答案
这会调出桌面当前选中文件的上下文菜单:
This will bring up the context menu of the currently selected file of the desktop:
tell application "Finder"
set sel to get the selection
if (sel is {}) then
log "Nothing selected! Can't proceed"
return
end if
set target_item_name to the name of (item 1 of sel)
end tell
tell application "System Events"
tell process "Finder"
tell group 1 of scroll area 1
set target to the first image whose value of attribute "AXFilename" is target_item_name
tell target to perform action "AXShowMenu"
end tell
end tell
end tell
*在 10.8.5 脚本编辑器中测试
这篇关于使用 AppleScript 和 Automator 在带有键盘的 Mac 上显示上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!