|Dec 18, 2012, 04:39 PM||#1|
AppleScript: Set variable to every XML element of a given name
Dear fellow AppleScript programmers,
I have an iOS app that has recipes. Each recipe can be organized by course or by cuisine. Each course and cuisine have their own table view and controller. I need to make sure each recipe is linked to a course and cuisine. Since a storyboard is really an XML file containing all the UI elements, I figured I could create an AppleScript that searches all the table view cells to make sure that all recipes are linked to two table view cells.
Here is my code:
set the_file to ((choose file without invisibles) as string) tell application "System Events" set xml_data to contents of XML file the_file tell xml_data to set tableViewCells to every XML element of xml_data whose name is "tableViewCell" tell xml_data to set subViews to every XML element of tableViewCells whose name is "subviews" tell xml_data to set viewLinks to every XML element of subViews whose name is "view" tell xml_data to set viewControllers to every XML element whose name is "viewController" tell xml_data to set views to every XML element of viewControllers whose name is "view" tell xml_data to set navItems to first XML element of views whose name is "navigationItem" tell xml_data to set recipes to value of XML attribute "title" of XML element navItems end tell
I could do the job myself, but I just don't want to.
The funny thing about this signature is that by the time you get to the end of it, you will have spent between five and ten seconds doing so.
|Thread Tools||Search this Thread|
All times are GMT -5. The time now is 08:03 PM.