In Applescript, I'm trying to activate a menu item in Seamonkey
I'm new to Applescript. I've done some searching and reading and found something that is supposed to work for activating a menu item:
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 a开发者_如何学Pythonpp_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")
When I run that the event log window shows:
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
Result: false
I don't see what I'm doing wrong.
Error number -1728 seems to be a generic "not found" error in AppleScript. I don't see a Windows menu in SeaMonkey, but I do see a Window menu. Try dropping the "s" from Windows.
Also, I think you might need to enable "access for assistive devices" for the "click" to work, you'll get an error message to that effect if you need to.
@mu is too short has it correct. Remove the 's' from 'Windows' and it will work. Here's the condensed version though if you don't want to deal with using handlers.
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
精彩评论