andrewn
-
Posts
3 -
Joined
-
Last visited
Content Type
Blogs
Gallery
Downloads
Events
Profiles
Forums
Articles
Media Demo
Posts posted by andrewn
-
-
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 -
Hi,The XML I'm outputting from my Javascript Script Filter is causing an error by I can't figure out what the issue is.I have similar code working fine as a Ruby Script Filter. It takes a string input e.g. "this is an example", transforms it to "this-is-an-example" and outputs the XML so it can be copied to the clipboard.I've tried to convert it to use the JS Script Filter but it gives the following error in the workflow debugger and doesn't trigger the action in Alfred:
Starting debug for 'filename'
[STDERR: alfred.workflow.input.scriptfilter] <?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>Here's the Ruby script that works correctly:Language: /usr/bin/rubyBehaviour: Terminate previous scriptQueue delay: Immediately after every character typesScript:
filename = "{query}".downcase.gsub(' ', '-')
puts(<<-EOT)
<?xml version="1.0"?>
<items>
<item valid="YES" autocomplete="#{filename}">
<title>#{filename}</title>
<text type="copy">#{filename}</text>
<text type="large type">#{filename}</text>
</item>
</items>
EOTAnd this is the JS equivalent that doesn't work:Language: /usr/bin/osascript (JS)Behaviour: Terminate previous scriptQueue delay: Immediately after every character typesScript:
var filename = "{query}".toLowerCase().replace(/ /g, '-');
var xml = [
'<?xml version="1.0"?>',
'<items>',
'<item valid="YES" autocomplete="#{filename}">',
'<title>#{filename}</title>',
'<text type="copy">#{filename}</text>',
'<text type="large type">#{filename}</text>',
'</item>',
'</items>'
].join('\n').replace(/#\{filename\}/g, filename);
console.log(xml);Any ideas what I'm doing wrong? Happy to post any more debugging info if needed.Thanks
XML output from JavaScript Script Filter logs error
in Workflow Help & Questions
Posted
That works great thanks. I didn't realise that osascript returns the last line of the script.
Also, thanks for the tip about run() being run!