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