2011-04-14 58 views
0

我是Applescript的新手。我做了一些搜索,閱讀和發現的東西,應該用於激活菜單項工作:在Applescript中,我試圖激活Seamonkey中的一個菜單項。

on do_menu(app_name, menu_name, menu_item) 
    try 
     -- bring the target application to the front 
     tell application app_name 
      activate 
     end tell 
     tell application "System Events" 
      tell process app_name 
       tell menu bar 1 
        tell menu bar item menu_name 
         tell menu menu_name 
          click menu item menu_item 
         end tell 
        end tell 
       end tell 
      end tell 
     end tell 
     return true 
    on error error_message 
     return false 
    end try 
end do_menu 

-- In my case I want to start Seamonkey and open the Composer window (and select it) so I 
-- do: 
do_menu("SeaMonkey", "Windows", "Composer") 

當我運行該事件日誌窗口顯示:

tell application "SeaMonkey" 
    activate 
end tell 
tell application "System Events" 
    click menu item "Composer" of menu "Windows" of menu bar item "Windows" of menu bar 1 of process "SeaMonkey" 
     --> error number -1728 from «class mbri» "Windows" of «class mbar» 1 of «class prcs» "SeaMonkey" 
end tell 

結果: 假

我看不出我做錯了什麼。

回答

1

錯誤號-1728似乎是AppleScript中的一個通用「未找到」錯誤。我在SeaMonkey中看不到Windows菜單,但我確實看到一個窗口菜單。嘗試從Windows中刪除「s」。

另外,我認爲您可能需要啓用「訪問輔助設備」以使「點擊」工作,如果需要,您將收到一條錯誤消息。

0

@mu太短,它是正確的。從'Windows'中刪除's',它會起作用。雖然如果你不想處理使用處理程序,這是精簡版本。

activate application "SeaMonkey" 
tell application "System Events" 
    tell process "SeaMonkey" 
     click menu item "Composer" of menu 1 of menu bar item "Window" of menu bar 1 
    end tell 
end tell 
相關問題