Applescript点击'分享dropbox链接'使用上下文菜单

时间:2014-12-08 01:27:44

标签: applescript dropbox

我正在尝试使用AXShowMenu访问特定保管箱文件夹中特定文件的上下文菜单的“共享保管箱链接”项。

我找到了以下脚本。通过Applescript right click a file

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

这似乎可以解决桌面项目的问题,

但如何使用此功能定位文件夹中的特定文件,然后点击上下文菜单中的“共享保管箱链接”?

1 个答案:

答案 0 :(得分:3)

有点kludgey,但确实有效。这要求您在Finder中打开和最前面的Dropbox文件夹。

tell application "Finder"
    activate --brings Finder to front
    select item 1 of window 1 --selects the first item in the list ; not sure how you want to select/determine the item
end tell
delay 0.5 --this is to insure you don't get unwanted typing in script editor (makes sure Finder activates before kludgey typing gets done)
tell application "System Events"
    tell application process "Finder"
        set _selection to value of attribute "AXFocusedUIElement" --focused element (selected element)
        tell _selection to perform action "AXShowMenu" --contextual menu
    end tell
    keystroke "share dropbox link" --type to select contextual menu item
    keystroke return --select it by hitting return
end tell

[编辑] 以下是确保您的Dropbox文件夹在Finder中处于最前端和最前端的技巧:

tell application "Finder"
    activate --brings Finder to front
    tell me to set dbFolder to POSIX file ((do shell script "cd ~/Dropbox/;pwd") & "/")
    open dbFolder
    select item 1 of window 1 --selects the first item in the list ; not sure how you want to select/determine the item
end tell

tell application "System Events"
    tell application process "Finder"
        set _selection to value of attribute "AXFocusedUIElement" --focused element (selected element)
        tell _selection to perform action "AXShowMenu" --contextual menu
    end tell
    keystroke "share dropbox link" --type to select contextual menu item
    keystroke return --select it by hitting return
end tell

可能有另一种选择上下文菜单的方式,但这是我在一杯酒之后到目前为止深夜所提出的。