2010-11-22 46 views
2

我試圖創建一個小的applescript,它將啓動DVD Player應用程序,然後將其調整爲其實際大小。代碼如下所示。當我運行代碼時,DVD播放器會啓動,但不會調整窗口的大小。我錯過了什麼讓這個工作?AppleScript:如何啓動應用程序,然後執行菜單命令

感謝, 羅布

do_menu("DVD Player", "View", "Actual Size") 

on do_menu(app_name, menu_name, menu_item) 
    try 
     -- bring the target application to the front 
     tell application app_name 
      activate 
     end tell 
     delay 3 
     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 

回答

2

你看過DVD播放機的字典嗎? 有調整大小的屬性。

這將打開它,然後進入全屏模式:

tell application "DVD Player" 
    open 
    delay 2 
    set viewer full screen to true 
end tell 

還是存在,其中列明瞭觀衆的大小屬性: 觀衆尺寸(半/正常/雙/最大):要設置的瀏覽器尺寸

所以,你可以用這個去實際尺寸:

這是你想做的事?

+0

+1爲詞典建議。 – 2010-11-22 15:39:43

+0

梅森 - 感謝您的幫助和有關AppleScript詞典的知識 – calmcajun 2010-11-23 02:25:37

+0

不客氣。 – 2010-11-24 00:47:07

0

我不是在一臺Mac的前面,所以我真的不能測試你的代碼,但我的建議是嘗試現有的和行之有效的執行相同的功能,它採用遞歸而不是嵌套:

http://hints.macworld.com/article.php?story=20060921045743404


它也可能是您的delay 3不夠長的DVD播放器應用程序完全加載,然後再開始嘗試編寫菜單事件。您可以嘗試通過運行兩個單獨的腳本來調試,並在加載DVD Player應用程序後查看您的菜單激活代碼是否可用。

相關問題