2014-12-08 2 views
1

Я пытаюсь получить доступ к контекстному меню определенного файла в определенной папке Dropbox с помощью AXShowMenu.Applescript click 'share dropbox link' с использованием контекстного меню

Я нашел следующий скрипт. Via 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 

Что, кажется, сделать трюк для элементов рабочего стола,

, но как я могу использовать это, чтобы ориентироваться на конкретные файлы в папках, то нажмите на ссылку «Поделиться ссылкой» в идентификации контента контекстного меню?

ответ

3

Немного kludgey, но он действительно работает. Для этого необходимо, чтобы папка Dropbox открывалась и находилась в самой верхней части 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 

[EDIT] Вот трюк, чтобы убедиться, что ваша папка 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 

Там может быть другой способ выбора контекстного меню, но это что я придумал до поздней ночи после бокала вина.

+0

Кроме того, вам действительно нужно проверить, действительно ли работает приложение Dropbox, прежде чем делать это. – CRGreen

+0

Работает для меня! спасибо CRG – MonkeyCMonkeyDo

+0

Добро пожаловать! Рад помочь. – CRGreen

Смежные вопросы