显示Mac上的上下文菜单使用AppleScript和Automator键盘 [英] Show context menu on Mac with keyboard using AppleScript and Automator

查看:1043
本文介绍了显示Mac上的上下文菜单使用AppleScript和Automator键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法来打开Finder中的上下文菜单在Mac上与优山美地的没有触摸鼠标/触摸板。

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于计算器发现,如果我运行它的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

这篇关于显示Mac上的上下文菜单使用AppleScript和Automator键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆