gpt4 book ai didi

macos - Applescript:执行上下文菜单操作

转载 作者:行者123 更新时间:2023-12-04 17:32:19 24 4
gpt4 key购买 nike

很抱歉我想不出一个更好的标题。我做了一个小的 applescript 服务,它获取您在 Finder 中选择的文件的 unix 路径,然后将该路径存储在剪贴板中。我使用它的文件在我的 Google Drive 卷中,现在我想添加一个由 Google Drive File Stream 应用程序提供支持的额外功能。

如果我在查找器中右键单击 Google Drive 文件,我会在上下文菜单中看到 3 个额外的项目,请参阅随附的屏幕截图。我想要的只是运行“将链接复制到剪贴板”的脚本。

那么我该如何告诉 apple script 这样做呢?对于这个非常琐碎的问题,我深表歉意,但我认为我缺乏正确的术语来进行 Google 搜索,我所能找到的只是如何将苹果脚本添加到上下文菜单中,我已经这样做了。

Google Drive - Finder context menu

最佳答案

使用 AXShowMenu 打开上下文菜单。然后发送击键“将链接复制到剪贴板”以选择复制操作,并发送“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

请注意,这在使用 Finder 的图标 View 时无法正常工作。必须使用 ListView 或列 View 。

关于macos - Applescript:执行上下文菜单操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58409124/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com