首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Applescript中,我正在尝试激活Seamonkey中的菜单项

在Applescript中,我正在尝试激活Seamonkey中的菜单项
EN

Stack Overflow用户
提问于 2011-04-14 09:29:42
回答 2查看 966关注 0票数 0

我是Applescript的新手。我做了一些搜索和阅读,发现了一些可以激活菜单项的东西:

代码语言:javascript
复制
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")

当我运行该命令时,事件日志窗口显示:

代码语言:javascript
复制
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

我看不出我做错了什么。

EN

回答 2

Stack Overflow用户

发布于 2011-04-14 10:01:29

错误号-1728在AppleScript中似乎是一个通用的“找不到”错误。我在SeaMonkey中看不到Window菜单,但我确实看到了Window菜单。尝试从Windows中删除“%s”。

另外,我认为你可能需要启用"access for assistive“才能让"click”生效,如果你需要的话,你会收到一条错误消息。

票数 1
EN

Stack Overflow用户

发布于 2011-04-15 00:38:42

@mu太短了,这是对的。从“Windows”中删除“%s”,它将正常工作。不过,如果您不想使用处理程序,这里是精简版本。

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5657604

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档