我是Applescript的新手。我做了一些搜索和阅读,发现了一些可以激活菜单项的东西:
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结果: false
我看不出我做错了什么。
发布于 2011-04-14 10:01:29
错误号-1728在AppleScript中似乎是一个通用的“找不到”错误。我在SeaMonkey中看不到Window菜单,但我确实看到了Window菜单。尝试从Windows中删除“%s”。
另外,我认为你可能需要启用"access for assistive“才能让"click”生效,如果你需要的话,你会收到一条错误消息。
发布于 2011-04-15 00:38:42
@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 tellhttps://stackoverflow.com/questions/5657604
复制相似问题