开发者

AppleScript: How do I launch an application and then execute a menu command

开发者 https://www.devze.com 2023-01-26 11:27 出处:网络
I am trying to create a small applescript which will launch the DVD Player application and then resize it to its Actual Size. The code is listed below. When I run the code the DVD Player launches but

I am trying to create a small applescript which will launch the DVD Player application and then resize it to its Actual Size. The code is listed below. When I run the code the DVD Player launches but it does not resize the window. What am I missing to get this to work?

Thanks, Rob

 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
                          开发者_StackOverflow社区  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


Have you looked at the dictionary for DVD Player? There are properties for adjusting the size.

This will open it and go full screen:

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

Or there is the viewer size property which states: viewer size (half/normal/double/max) : To set the the viewer size

So you could use this to go to Actual Size:

tell application "DVD Player"
   open
   delay 2
   set viewer size to normal
end tell

Is that what you wanted to do?


I'm not in front of a Mac so I can't really test your code, but my suggestion is to try an existing and proven implementation of the same functionality, which uses recursion rather than nesting:

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


It's also possible that your delay 3 is not long enough for the DVD Player application to completely load before you start trying to script menu events. You could try debugging this by running two separate scripts and see if your menu-activation code works once the DVD Player app is loaded.

0

精彩评论

暂无评论...
验证码 换一张
取 消