I'm using this example as a way of trying out the OSAScript JS integration in the latest Alfred release.
Thanks to your help, I've figured out that in Apple's JS OSAScript host, console.log outputs to stderr.
A convoluted way to output to stdout seems to be:
ObjC.import('stdio');
$.printf('this string outputs to stdout');
So, I can get the script working with this:
ObjC.import('stdio');
var filename = '{query}'.toLowerCase().replace(/ /g, '-');
var xml = [
'\n<?xml version="1.0"?>',
'<items>',
'\t<item valid="YES" autocomplete="#{filename}">',
'\t\t<title>#{filename}</title>',
'\t\t<text type="copy">#{filename}</text>',
'\t\t<text type="largetype">#{filename}</text>',
'\t</item>',
'</items>'
].join('\n').replace(/#\{filename\}/g, filename);
$.printf(xml);
However, printf returns an int of the number of chars in the string and so Alfred now complains about this:
[ERROR: alfred.workflow.input.scriptfilter] XML Parse Error 'The operation couldn’t be completed. (NSXMLParserErrorDomain error 5.)'. Row (null), Col (null): 'Extra content at the end of the document' in XML:
<?xml version="1.0"?>
<items>
<item valid="YES" autocomplete="example-input">
<title>example-input</title>
<text type="copy">example-input</text>
<text type="largetype">example-input</text>
</item>
</items>215