2013-04-28 67 views
0

我編寫了這個AppleScript,通過從列表對話框中選擇從'最近的項目'子菜單中打開選定的項目。它適用於第一個項目,然後優雅地退出,打開其他項目。在最近項目中打開文檔子菜單

你會在下面看到,我添加了一些'顯示對話框'給我一個想法,如果它應該工作,並且一切都表明它應該。不過,這不...

tell application "Finder" 
    activate 
    try 
     tell application "System Events" 
      tell process "Finder" 
       tell menu "Recent Items" of menu item "Recent Items" of menu 1 of menu bar 1 
        set menuItemNames to (get name of (every menu item whose position ≠ missing value and name ≠ "Applications" and name ≠ "Documents" and name ≠ "Servers" and name ≠ missing value)) 
        set text item delimiters of AppleScript to "," 
        set targetMenuItems to (choose from list menuItemNames with prompt "Choose a recent document to view:" with title "Recent Documents" OK button name "Open" with multiple selections allowed) as list 
        set targetMenuItems to (text items of targetMenuItems as text) 
        if targetMenuItems ≠ "false" then 
         set menuitemCount to (count text items in targetMenuItems) 
         display dialog menuitemCount 
         display dialog (text item 1 of targetMenuItems) 
         set x to 1 
         repeat menuitemCount times 
          set targetItem to (text item x of targetMenuItems) 
          display dialog targetItem 
          click menu item targetItem 
          set x to x + 1 
         end repeat 
        end if 
       end tell 
      end tell 
     end tell 
    on error errorMsg 
     display dialog errorMsg 
    end try 
end tell 

回答

0

我可能會丟失一些原因列表轉換爲文本,但這似乎與多個項目的工作:

delay 0.3 
tell application "System Events" to tell (process 1 where it is frontmost) 
    tell menu 1 of menu item "Recent Items" of menu 1 of menu bar 1 
     set menuitems to name of (menu items where position is not missing value and name is not "Applications" and name is not "Documents" and name is not "Servers" and name is not "Clear Menu" and name is not missing value) 
     tell application (path to frontmost application as text) 
      activate 
      choose from list menuitems with multiple selections allowed 
     end tell 
     repeat with m in result 
      click menu item m 
     end repeat 
    end tell 
end tell 
+0

這似乎很好地工作,只要你在開始處添加'tell application'Finder'來激活',謝謝你的幫助! – AppleScripter 2013-04-28 20:37:25

相關問題