AppleScript:如何启动应用程序然后执行菜单命令

发布于 2024-10-04 04:56:54 字数 862 浏览 3 评论 0原文

我正在尝试创建一个小 applescript,它将启动 DVD 播放器应用程序,然后将其大小调整为实际大小。代码如下所示。当我运行代码时,DVD 播放器会启动,但不会调整窗口大小。为了让它发挥作用,我缺少什么?

谢谢, 抢

 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

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
                            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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

对风讲故事 2024-10-11 04:56:54

你看过DVD播放器的字典吗?
有用于调整大小的属性。

这将打开它并进入全屏:

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

或者查看器大小属性指出:
查看器大小(一半/正常/双倍/最大):设置查看器大小

因此您可以使用它转到实际大小:

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

这是您想要做的吗?

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?

沉溺在你眼里的海 2024-10-11 04:56:54

我不在 Mac 前面,所以我无法真正测试您的代码,但我的建议是尝试相同功能的现有且经过验证的实现,它使用递归而不是嵌套:

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

也有可能您的delay 3 不够长,无法在您开始尝试编写菜单事件脚本之前完全加载 DVD 播放器应用程序。您可以尝试通过运行两个单独的脚本来调试此问题,并在加载 DVD 播放器应用程序后查看菜单激活代码是否有效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文