2014-12-08 46 views
1

我試圖使用AXShowMenu訪問「共享下拉框鏈接」項目特定文件夾中特定文件的上下文菜單。Applescript使用上下文菜單點擊'共享下拉框鏈接'

我找到了下面的腳本。通過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 

這似乎做桌面項目的伎倆,

,但我怎麼可以使用此目標文件夾中的特定文件,然後單擊上下文菜單中的「共享Dropbox的鏈接」?

回答

3

有點kludgey,但它確實有效。這要求您在Finder中打開並放置保管箱文件夾。

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文件夾是開放的,最前面的搜索工具:

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 

有可能是選擇上下文菜單中的另一種方式,但這是我在深夜喝了一杯葡萄酒後纔想到了什麼。

+0

另外,在做這件事之前,你真的應該檢查實際正在運行的保管箱應用程序。 – CRGreen 2014-12-08 09:38:31

+0

適合我!謝謝CRG – MonkeyCMonkeyDo 2014-12-09 03:15:35

+0

不客氣!很高興有幫助。 – CRGreen 2014-12-09 06:50:06