简体   繁体   English

Applescript:执行上下文菜单操作

[英]Applescript: do a context menu action

I'm sorry I couldn't come up with a better title.对不起,我想不出一个更好的标题。 I've made a little applescript service that gets the unix path to a file you selected in the Finder and then stores that path in the clipboard.我制作了一个小 applescript 服务,它获取 unix 路径到您在 Finder 中选择的文件,然后将该路径存储在剪贴板中。 The files I use this for are in my Google Drive volume and now I'd like to add an extra feature which is powered by Google Drive File Stream application.我使用它的文件在我的 Google Drive 卷中,现在我想添加一个由 Google Drive File Stream 应用程序提供支持的额外功能。

If I right click on a Google Drive file in the finder, I get 3 extra items in the context menu, see attached screenshot.如果我在查找器中右键单击 Google Drive 文件,我会在上下文菜单中获得 3 个额外的项目,请参见随附的屏幕截图。 All I want is my script to run "Copy link to clipboard".我想要的只是我的脚本来运行“复制链接到剪贴板”。

So how do I tell apple script to do so?那么我如何告诉苹果脚本这样做呢? I'm sorry for the very trivial question, but I think I lack the right terminology to make a Google search, all I could find was how to add an apple script to a context menu, which I already did.对于这个非常琐碎的问题,我很抱歉,但我认为我缺乏正确的术语来进行谷歌搜索,我所能找到的只是如何将苹果脚本添加到上下文菜单中,我已经这样做了。

Google Drive - Finder 上下文菜单

Use AXShowMenu to open the context menu.使用AXShowMenu打开上下文菜单。 Then send the keystroke "Copy link to clipboard" to select the copy action, and send "Enter" to activate the action.然后将击键“复制链接到剪贴板”发送到 select 复制动作,并发送“Enter”以激活该动作。

tell application "System Events" to tell application process "Finder"
    set selectedFile to value of attribute "AXFocusedUIElement"
    tell selectedFile to perform action "AXShowMenu"
    delay 0.5
    keystroke "Copy link to clipboard"
    -- Sends enter
    key code 36
end tell

Note that this doesn't work properly when using Finder's icon view.请注意,这在使用 Finder 的图标视图时无法正常工作。 The list view or column view must be used.必须使用列表视图或列视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM