Jump to content

Setting variables in a python script doesn't work


Recommended Posts

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

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)

 

Link to comment
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...