I'm trying to code a script which can be able to extract the menu structure of a given app. This is a simplified working example:
tell application "System Events"
tell process "Terminal"
tell menu bar 1
set listA to name of every menu bar item
set listB to name of every menu of every menu bar item
set listC to name of every menu item of every menu of every menu bar item
set listD to name of every menu of every menu item of every menu of every menu bar item
set listE to name of every menu item of every menu of every menu item of every menu of every menu bar item
end tell
end tell
end tell
return {listA, listB, listC, listD, listE}
When I run this script on Script Editor, the result is a set of nested lists, like this (real result is too long, so I'm giving a sample):
{{{"Option1", "Option2", "Option3"}, {{"subOption1.1", "subOption1.2"}, {"subOption2.1", subOption2.2", "subOption2.3"}, {"subOption3.1"}}}
Thus, it's easy to know that menu Option1 has two items inside and so on...
But when I run this same script from python, using "osascript -e", the list structure and braces are gone, like this
{{"Option1", "Option2", "Option3"}, {"subOption1.1", "subOption1.2", "subOption2.1", subOption2.2", "subOption2.3", "subOption3.1"}}
So there is no way to know which sub-list corresponds to each other.
Is there a way to keep those braces or converting them into something different you can manage later on, or write this in a sort of "raw" data which keeps that nested structure?
Thanks in advance!