leahcim Posted January 23, 2020 Posted January 23, 2020 (edited) Hello I seem to have trouble understanding how outputs from scripts are digested by follow-up nodes. I have the following example: A NodeJS script (index.js) that is executed when entering a keyword (cut <text>) The script uses the Alfy package (same issue without the package) The script uses alfy.output('TEST') to write to STDOUT (same as console.error()) The script then passes its output on to a Post Nofification node which shows {query} The notification is displayed as: { "items": [ { "title": "ABC\n", "subtitle": "Press ⌘L to see the full error and ⌘C to copy it.", "valid": false, "text": { "copy": "```\nABC\n```\n\n-\nScript Output - Example 1.0.1\nAlfred 4.0.8\ndarwin 18.7.0", "largetype": "ABC" }, "icon": { "path": "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns" } } ] } { "items": "TEST" } This can also be seen in debug, as the whole output, i.e. all calls to STDOUT that happened within the script, are concatenated into a list of items. Then this list, formatted as JSON, is passed to the notification. My expectation was, that a) only the last alfy.output() (or console.error()) would be passed to the Notification node and b) the Notification node would display the text as is (e.g. 'TEST'), and not as a JSON string Obviously my understanding is incorrect. How can I simply display the 'TEST' output from the script in the notification? Apparently I cannot attach the complete workflow, so please find below screenshots: Keyword Run Script Post Notification index.js const alfy = require("alfy"); alfy.log('ABC') // Is also part of the JSON string - why? I only need the last alfy.output() / log() alfy.output('TEST') // Will be shown as { "items" ... } in notification Edited January 23, 2020 by leahcim
deanishe Posted January 23, 2020 Posted January 23, 2020 (edited) Hi @leahcim, welcome to the forum. If you're having a problem with a workflow, please upload the workflow somewhere (Dropbox?) and post a link, so we can have a look for ourselves. It's very difficult to diagnose issues with a workflow we don't have, and it's not really reasonable to expect us to try and re-create your workflow from a bunch of screenshots simply in order to help you. Especially when it's based on something non-standard like Node. 1 hour ago, leahcim said: My expectation was, that a) only the last alfy.output() (or console.error()) would be passed to the Notification node and b) the Notification node would display the text as is (e.g. 'TEST'), and not as a JSON string I don't know how Alfy works (the Alfy thread or its GitHub repo would be the best places to ask about that), but the default behaviour of a Notification is to display whatever the previous element wrote to STDOUT. If you write a bunch of JSON to STDOUT, then the Notification will show a bunch of JSON. There is a specific JSON format you can emit from a Run Script action if you need to set workflow variables (though Alfy doesn't support it), but if all you want to do is pass some text to a Notification, just write the text to STDOUT. Again, I don't know Alfy, but you appear to be using it incorrectly. Judging by the output you've posted, Alfy.output() seems to be only intended for use in Script Filters. Edited January 23, 2020 by deanishe
leahcim Posted January 23, 2020 Author Posted January 23, 2020 (edited) Hi @deanishe, thank you! Sure, I've uploaded the workflow here: https://gofile.io/?c=QkslSS Regarding Alfy, the example is similar even without, just using NodeJS' standard console.log(): console.log('TEST1') console.log('TEST2') With this code, while indeed no JSON structure will be displayed (apparently alfy.output() is only for JSON structures, unlike alfy.log()), the notification will still display all console.log() statements at once: TEST1 TEST2. How can I only pass TEST2, i.e. the last log element to the notification? Edited January 23, 2020 by leahcim
deanishe Posted January 23, 2020 Posted January 23, 2020 (edited) 8 minutes ago, leahcim said: How can I only pass TEST2, i.e. the last log element to the notification? You can't only pass the last of multiple messages. Everything you write to STDOUT is treated as input by Alfred, so if you don't want TEST1 to be passed to the Notification, you mustn't write it to STDOUT. If you're trying to log something, you should write it to STDERR instead. Then it will appear in Alfred's debugger. Alfy's docs say alfy.log() writes to STDERR. Edited January 23, 2020 by deanishe
leahcim Posted January 23, 2020 Author Posted January 23, 2020 (edited) Thanks @deanishe, that works! It seems to be an issue with Alfy then, as it prevents me from witing to STDERR instead of STDOUT. The following works: console.error('TEST1') // Writes to STDERR, not shown in notification console.error('TEST2') // Writes to STDERR, not shown in notification console.log('TEST3') // Writes to STDOUT, shown in notification But once I import Alfy it no longer works: const alfy = require("alfy"); console.error('TEST1') // Writes to STDOUT as JSON console.error('TEST2') // Writes to STDOUT as JSON console.log('TEST3') // Writes to STDOUT as plain text I will need to check the Alfy doc once again. Edited January 23, 2020 by leahcim
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now