Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 如何在不使用applescript打开的情况下获取弹出菜单中的项目数?_Macos_Automation_Applescript - Fatal编程技术网

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

Macos 如何在不使用applescript打开的情况下获取弹出菜单中的项目数?,macos,automation,applescript,Macos,Automation,Applescript,我想写一个脚本,以几种格式保存图像。问题是,格式是基于某些条件显示的。我的意思是,有时会有5种格式,有时会有8种。我想完全自动化这些保存东西的工作。所以我决定写一份申请书。使用UI浏览器,我可以访问每个弹出菜单。我正在使用循环执行保存操作。问题是我不知道该怎么结束。因此,我想到了一个想法,如果我能在弹出菜单中获得项目的数量,那么我将很容易执行任务 有人能帮我吗?这是可能的,但你不能直接数菜单项。通信在GUI端进行,而不是直接与应用程序进行通信,这意味着需要先显示菜单,然后才能进行计数 tell

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


有人能帮我吗?

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

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
计数是检查菜单的一种方法,但另一种方法是获取菜单中的所有值,然后按其名称单击右菜单项。一般来说,这可能不是你的最佳解决方案

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