Jump to content

andrewn

Member
  • Posts

    3
  • Joined

  • Last visited

andrewn's Achievements

Helping Hand

Helping Hand (3/5)

0

Reputation

  1. 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!
  2. 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
  3. 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/ruby Behaviour: Terminate previous script Queue delay: Immediately after every character types Script: 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> EOT And this is the JS equivalent that doesn't work: Language: /usr/bin/osascript (JS) Behaviour: Terminate previous script Queue delay: Immediately after every character types Script: 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
×
×
  • Create New...