首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在不使用applescript打开的情况下获取弹出菜单中的项目数?

如何在不使用applescript打开的情况下获取弹出菜单中的项目数?
EN

Stack Overflow用户
提问于 2012-11-16 19:47:55
回答 1查看 2.3K关注 0票数 0

我想写一个脚本,保存几种格式的图像。问题是,格式是基于某种条件显示的。我的意思是有时会有5种格式,有时会有8种。我想完全自动化这些保存的东西的工作。所以我决定写一个applescript。得到UI浏览器,并使用它,我可以访问每一个弹出菜单。我正在使用循环来执行保存操作。问题是,我不知道该从哪里说起。所以我想到了一个想法,如果我能得到弹出菜单中的项目数,那么我就可以很容易地执行任务。

有人能帮我吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-16 20:49:42

嗯,这是可能的,但您不能直接计算菜单项。通信是在GUI端进行的,而不是直接与应用程序通信,这意味着菜单需要先出现,然后才能计数。

代码语言:javascript
运行
复制
tell application "System Events"
    tell process "Your application"
        --we need to menu to appear first
        click pop up button 1 of window 1
        --now the menu appeared we can count the items in it
        count menu items of menu 1 of pop up button 1 of window 1
        --now hide the menu again by pressing escape
        key code 53
    end tell
end tell

计数是检查菜单的一种方法,但另一种方法是获取菜单中的所有值,然后单击右菜单项的名称。通常情况下,这可能不是最好的解决方案。

代码语言:javascript
运行
复制
set menuItemToSelect to "Title of menu item I prefer to check"

tell application "System Events"
    tell process "Your Application"
        tell pop up button 1 of window 1
            --Only continue if the menu item isn't already selected
            if value of it is not equal to menuItemToSelect then
                --we need to menu to appear first
                click it
                --now the menu appeared we can get the items
                set menuItemTitles to name of menu items of menu 1
                --check if the menu item exists
                if menuItemToSelect is in menuItemTitles then
                    --menu item exists; click on it
                    click menu item menuItemToSelect of menu 1
                else
                    --the menu item to select doesn't exist; hide the menu
                    key code 53
                end if
            end if
        end tell
    end tell
end tell
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13415994

复制
相关文章

相似问题

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