villi Posted June 8, 2022 Share Posted June 8, 2022 I'm new to making workflows using python scripts. I am trying to set som variables inside a python file that runs through the the "run scripts" block. However I can't get it to work, and I don't know what I'm doing wrong. import sys import re import json query = sys.argv[1] data = { "alfredworkflow": { "arg": "", "config": { }, "variables": { "a": "test" } } } json.dump(data, sys.stdout) The python file outputs isn't able to parse the JSON, and instead just outputs it as a string: "{"alfredworkflow": {"arg": "", "config": {}, "variables": {"a": "test"}}}". And when I use {var:a} in a notification block, it's empty. [16:32:12.639] Notion quick add[Keyword] Processing complete [16:32:12.640] Notion quick add[Keyword] Passing output 'input' to Run Script [16:32:12.695] Notion quick add[Run Script] Processing complete [16:32:12.714] Notion quick add[Run Script] Passing output '{"alfredworkflow": {"arg": "", "config": {}, "variables": {"a": "test"}}}input ' to Post Notification Link to comment
giovanni Posted June 8, 2022 Share Posted June 8, 2022 that last input part doesn't seem valid JSON.... where is input supposed to be? Link to comment
vitor Posted June 9, 2022 Share Posted June 9, 2022 Welcome @villi, You have unnecessary code your snippet. Unless input is supposed to come into play. But if it is, as @giovanni noted it’s not clear what it’s supposed to refer to. With the given information, this should work: import sys import json data = { "alfredworkflow": { "variables": { "a": "test" } } } json.dump(data, sys.stdout) villi 1 Link to comment
villi Posted June 9, 2022 Author Share Posted June 9, 2022 9 hours ago, vitor said: Welcome @villi, You have unnecessary code your snippet. Unless input is supposed to come into play. But if it is, as @giovanni noted it’s not clear what it’s supposed to refer to. With the given information, this should work: import sys import json data = { "alfredworkflow": { "variables": { "a": "test" } } } json.dump(data, sys.stdout) @vitor Thanks! Don't know what the difference between your code and mine was, but it somehow works now! Link to comment
Sam Michel Posted July 15, 2022 Share Posted July 15, 2022 Legends! Thanks so much for posting this here. I've been looking for docs on the JSON object for the workflow for ages and no amount of Googling yielded anything until I found this solution which worked a treat. It's incredibly useful for validating and calculating variables which can be used later in the workflow. Thanks again. Link to comment
vitor Posted July 15, 2022 Share Posted July 15, 2022 8 minutes ago, Sam Michel said: I've been looking for docs on the JSON object for the workflow It’s documented on the help pages. Sam Michel 1 Link to comment
Vero Posted July 15, 2022 Share Posted July 15, 2022 @Sam Michel As a heads-up alongside Vítor's response (for you and anyone else who comes across this thread), every workflow object has a question mark icon in the configuration, which will take you to the documentation for that specific object This is the best starting point for insight on configuring that particular workflow object! Sam Michel 1 Link to comment
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