[ANN]Script Helper App

FYI, version 1.9.14 is now out. It is now Gatekeeper-friendly in Mavericks, and has a couple of other bug fixes. Download in the usual places, or choose Check for Updates… from the menu.

Can someone verify that the ‘extract from XML’ command in AsObjC Runner actually can take an XML string as its primary operand as it documents in the dictionary? I’m trying to use the ‘extract’ from XML’ command and it is working if I specify a file path. However, when I give it an XML string, it returns this error:

(where the ellipsis is hiding the rest of the raw XML.

It would be useful to successfully run this against a string that I read into memory instead of accessing the file multiple times, as I believe that would run faster.

As reference for anyone else reading this, here’s the dictionary entry:

extract from XML any : the XML data to extract from. Can be an alias, file, HFS path or POSIX path, or the XML as a string.
matching text or list of text : XPath expression(s) describing the XML nodes to extract.
[expression text or list of text] : XPath expression(s) applied to the extracted node set (when not specified, the extracted node set is returned as XML).
[including output element boolean] : Whether to wrap the resulting XML in element. Default is true, but ignored if the query is for attributes.

It will accept an XML string, but the string must be valid XML. That means it must start with the usual XML declaration: “<?xml version=…”

Thank you! That worked! Interesting that the functions work on files that do not have an XML declaration, but the strings do not. Was that intentional, to avoid needing to edit XML files that didn’t bother to have a declaration, whereas with strings it makes more sense to be strict, since a declaration can be prepended more easily if missing?

No, nothing like that. I needed some way to tell if a passed string was a file path or XML, and I happened to check for a prefix of “<?xml” as a convenient method. I’m a bit surprised (pleasantly) that it’s not required for files, but that’s Cocoa’s doing.

If you’re running Mavericks, it’s pretty simple to do it yourself using AppleScriptObjC.