我想写一个脚本,保存几种格式的图像。问题是,格式是基于某种条件显示的。我的意思是有时会有5种格式,有时会有8种。我想完全自动化这些保存的东西的工作。所以我决定写一个applescript。得到UI浏览器,并使用它,我可以访问每一个弹出菜单。我正在使用循环来执行保存操作。问题是,我不知道该从哪里说起。所以我想到了一个想法,如果我能得到弹出菜单中的项目数,那么我就可以很容易地执行任务。
有人能帮我吗?
发布于 2012-11-16 20:49:42
嗯,这是可能的,但您不能直接计算菜单项。通信是在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 tellhttps://stackoverflow.com/questions/13415994
复制相似问题