Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old Dec 18, 2012, 04:39 PM   #1
moonman239
macrumors 65816
 
Join Date: Mar 2009
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:

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
When I try to run this code, I get the error "Can't get every element of {} whose name = "subviews"". I just don't get why the fourth line of code results in tableViewCells being set to nothing useful. The tag names are correct.

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.
moonman239 is offline   0 Reply With Quote

 
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
String and variable concatenation in AppleScript tekboi Mac Programming 6 Apr 15, 2014 02:37 PM
Applescript newb: declaring a variable in another script. Vanilla Face Mac Programming 2 Jan 5, 2014 08:39 PM
How to set environmental variable? hajime Mac Basics and Help 3 Sep 28, 2013 10:33 PM
How do I set the position of an element relative to another element? moonman239 Web Design and Development 3 Mar 3, 2013 05:30 PM
(AppleScript) "Tell"-ing every XML element to do something moonman239 Mac Programming 2 Jan 3, 2013 05:06 PM

Forum Jump

All times are GMT -5. The time now is 02:39 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC