AppleScript:如何启动应用程序然后执行菜单命令
我正在尝试创建一个小 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你看过DVD播放器的字典吗?
有用于调整大小的属性。
这将打开它并进入全屏:
或者查看器大小属性指出:
查看器大小(一半/正常/双倍/最大):设置查看器大小
因此您可以使用它转到实际大小:
这是您想要做的吗?
Have you looked at the dictionary for DVD Player?
There are properties for adjusting the size.
This will open it and go full screen:
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:
Is that what you wanted to do?
我不在 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.