2013-12-19 49 views
1

非常简单的问题,但我试图点击菜单中列表中的菜单项 - 即单击菜单中的“文本编码”会调出不同种类的编码列表。我想用applescript选择某种编码。这是我的尝试:Applescript点击嵌套菜单项

tell application "System Events" to tell process "iChm" 
    click menu item "Text Encoding" of menu "View" of menu bar item "View" of menu bar 1 
    click menu item 2 of last menu item 
end tell 

非常感谢!

+0

对不起,我知道它可能是一个愚蠢的问题 - 尽管我找不到答案! – luliger

+0

您是否检查以确保UI元素已启用?我不记得“iChm”是什么过程,所以这是我现在可以提出的问题。 – fireshadow52

+0

您好,感谢您的回复。 iChm只是一个chm文件阅读器。我想单击工具栏中两个级别中的项目之一 - 如果有意义的话?此外,我尝试了一个级别中的项目的脚本(例如编辑菜单“全选”),并且发现只有在点击工具栏中的“编辑”后才会执行该脚本。谢谢 – luliger

回答

1
tell application "System Events" to tell process "iChm" 
    tell menu item "Text Encoding" of menu 1 of menu bar item "View" of menu bar 1 
     click menu item 3 of menu 1 
    end tell 
end tell 

对于需要先点击菜单栏项目一些菜单项:

tell application "System Events" to tell (process 1 where it is frontmost) 
    tell menu bar item 3 of menu bar 1 
     click 
     click menu item "Open Recent" of menu 1 
    end tell 
end tell 
0

我认为这将是很高兴知道你想要点击什么。如果是 “的Unicode(UTF-8)” 项,注意到有(由开发人员可能是O型)的Unicode后两个空间:

"Unicode (UTF-8)" 
     ^^ 

所以,如果你这样做:

tell application "System Events" 
    click menu item "Unicode (UTF-8)" of menu "Text Encoding" of menu item "Text Encoding" of menu "View" of menu bar item "View" of menu bar 1 of application process "iChm" 
end tell 

...它会工作。