0

画像をいくつかの形式で保存するスクリプトを書きたいです。ある条件に基づいてフォーマットが表示されるということです。つまり、5つのフォーマットが存在する場合もあれば、8つのフォーマットが存在する場合もあります。これらの節約機能の動作を完全に自動化したいのです。そこで、私はアップルスクリプトを書くことにしました。UIブラウザーを取得し、それを使用して、すべてのポップアップメニューにアクセスできます。保存操作を実行するためにループを使用しています。問題は、私がどこで終わらせるべきかわからないということです。そこで、ポップアップメニューの項目数がわかれば、やりやすいと思いました。

誰かが私を助けることができますか?

4

1 に答える 1

1

これは可能ですが、メニュー項目を直接数えることはできません。通信は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

よく数えることはメニューをチェックする1つの方法ですが、もう1つの方法は、メニュー内のすべての値を取得してから、その名前で適切なメニュー項目をクリックすることです。これは、おそらくあなたの場合ではないかもしれませんが、一般的に最良の解決策です。

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
于 2012-11-16T12:49:42.163 に答える