如何在不使用applescript的情况下获取弹出菜单中的项目数? [英] How to get the number of items in a pop-up menu without opening it using applescript?

查看:101
本文介绍了如何在不使用applescript的情况下获取弹出菜单中的项目数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个脚本,以几种格式保存图像.问题是格式是根据某些条件显示的.我的意思是有时会有5种格式,有时是8种.我想完全自动化这些保存的东西的工作.所以我决定写一个applescript.有UI浏览器,使用它我可以访问每个弹出菜单.我正在使用循环执行保存操作.事情是我没有到哪里结束.因此我想到,如果我可以在弹出菜单中获得项目数,那么对我来说执行任务就很容易.

I want to write a script which saves the images in few formats. the thing is the formats are shown based on some condition. I means some times there will be 5 formats and sometimes 8. I want to completely automate the working of these saving things. So i decided to write an applescript. Got UI browser and using that I can access each and every pop-up menus. I'm using loops to perform save operation. The thing is I am not getting where to end. So i came up with a thought that if i can get the number of items in the pop-up menu then it will be easy for me to carry out the task.

有人可以帮我吗?

推荐答案

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

Well this is possible but you can't count the menu items directly. Communication is at the GUI-end and not directly to the application which means that the menu needs to appear before you can count it.

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

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

Well counting is one way to check the menu but the other way is get all the values in it and then click the right menu item by it's name. This is, maybe not in your case, in general the best solution.

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

这篇关于如何在不使用applescript的情况下获取弹出菜单中的项目数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆