Re: [cocoa scripting] getting script class attribute name
Re: [cocoa scripting] getting script class attribute name
- Subject: Re: [cocoa scripting] getting script class attribute name
- From: Ken Victor <email@hidden>
- Date: Tue, 6 Sep 2005 12:34:30 -0700
dustin,
thanx very much. unfortunately, this isn't working for me. i always
get back a nodes array with 0 items! as far as i know, i successfully
create the NSXMLDocument *sdefDoc, and successfully get the root
element, but thats as far as it goes successfully. i say that i
successfully get the doc and root as no errors are reported and when
i look at them in the xcode debugger, they both looks like my sdef
file. however, if is use the print description to console menu
command for the root element, it prints as one continuous stream of
text, with no apparent (tree) structure. is this correct? (actually,
i do see a tree structure for a part of my sdef file that i have
commented out.)
thanx in advance for any help/insight you (or anyone) can provide,
ken
At Mon, 5 Sep 2005 17:26:09 -0700, Dustin Voss <email@hidden> wrote:
If you did want to parse the sdef file, you can use
OSACopyScriptingDefinition() to get it. This function is documented at:
http://developer.apple.com/documentation/Carbon/Reference/
Open_Scripti_Architecture/Open_Script_Arch/chapter_1.2_section_12.html
With the advent of NSXML, the parsing is trivial. You can use XPath
expressions to get the values you need:
http://developer.apple.com/documentation/Cocoa/Conceptual/
NSXML_Concepts/Articles/QueryingXML.html
For example, this should find the "frontmost" property:
// Get the bundle.
FSRef appRef;
CFDataRef sdefData;
CFURLRef appURL = CFBundleCopyBundleURL (CFBundleGetMainBundle());
CFURLGetFSRef (appURL, &appRef);
CFRelease (appURL);
// Get the SDEF.
NSError *err;
OSACopyScriptingDefinition (*appRef, kOSAModeNull, &sdefData);
NSXMLDocument *sdefDoc =
[[NSXMLDocument alloc] initWithData:(NSData *)sdefData options:0
error:&err];
NSXMLElement *sdefRoot = [sdefDoc rootElement];
CFRelease (sdefData);
// Get the property name.
NSArray *nodes = [sdefRoot nodesForXPath: @"//property[code=\"pisf\"]/
@name" error:&err];
NSString *name = [[nodes objectAtIndex:0] stringValue];
// Do something with 'name'.
// Clean up.
[sdefDoc release];
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden