Hi,
I have a piece of code that calls a procedure that traverses the View menu in Photos.app. At least that’s what I am trying to do. I can get the View Menu, click on the Collections menu item. When I go about to clicking on the Albums menu item under that, I have the following code
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "Photos" to activate
set root_menu_item to search_from_view_menu("Collections", true)
if root_menu_item = null then
display dialog "Collections not found"
end if
tell application "System Events" to tell process "Photos.app" to click root_menu_item
-- tell application "System Events" to tell process "Photos.app" to click menu 1 of menu_item
delay 2
set album_menu to search_menu_items("Albums", menus of root_menu_item, false)
if album_menu = null then
display dialog "Albums not found"
end if
tell application "System Events" to tell process "Photos.app" to click album_menu
-- tell application "System Events" to tell process "Photos.app" to click menu 1 of album_menu_item
on search_from_view_menu(search_name, return_item)
tell application "System Events" to tell application process "Photos"
set the_menu to item 1 of UI elements of menu bar item "View" of menu bar 1
set sub_search to my search_menu_items(search_name, the_menu, return_item)
if sub_search ≠ null then
return sub_search
end if
end tell
return null
end search_from_view_menu
on search_menu_items(searched_name, a_menu, return_item)
tell application "System Events"
set menu_items to menu items of a_menu
set child_count to count menu_items
if child_count > 0 then
set idx to 1
repeat count of menu_items times
set menu_item to item idx of menu_items
set item_name to name of menu_item
if searched_name is equal to item_name then
if return_item then
return menu_item
else
return menu 1 of menu_item
end if
else
repeat with element in menus of menu_item
set sub_search to my search_menu_items(searched_name, element, return_item)
if sub_search ≠ null then
return sub_search
end if
end repeat
end if
set idx to idx + 1
end repeat
end if
end tell
return null
end search_menu_items
My current difficulty is that when I am trying to do “menus of root_menu_item”, “menus” is considered a variable and not the highlighted to blue keyword that allows me to get the menus node under the “Albums” menu item.
If you look at the last repeat in the procedure code that does the traversal, I have a similar situation, and in that case the word “menus” is highlighted to blue and does what is expected.
Thanks,
Regards