我是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
结果:假
我不知道我做错了什么
错误号-1728似乎是AppleScript中一个通用的"not found"错误。我在SeaMonkey中没有看到Windows菜单,但我确实看到了Window菜单。试着从Windows中去掉"s"。
另外,我认为你可能需要启用"辅助设备访问"才能使"点击"工作,如果你需要的话,你会得到一个错误消息。
@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 tell