Jump to content

[SOLVED] How can I list out options using an output from a Python script?


Recommended Posts

Basically the title. I am using a python script which will return a list in one of its functions. How can I display the elements of that list as options in Alfred?

Example:

def func():
  #some code here
  return a # a = ["A", "B", "C", "D"] for example

 

How do I get "A", "B", "C", "D" to be the 4 options in an Alfred drop down like below:

 

image.png.3c3732d9902b1bc718eb615fb20f9eb1.png

Edited by abunav
Link to comment

Not quite sure how I can tie in the Python script here. What I want is that the python script be executed upon a keyword trigger, and the JSON object thus generated in the script be used as list items in Alfred.

Edited by abunav
Link to comment
10 hours ago, abunav said:

Not quite sure how I can tie in the Python script here.

 

Do you know how to generate JSON from Python? That’s all you need to do (send it to the standard output) in the specified format. For your example, it would be something like

 

{"items": [
    {
        "title": "A",
        "arg": "something to do with A"
    },
    {
        "title": "B",
        "arg": "something to do with B"
    },
    {
        "title": "C",
        "arg": "something to do with C"
    },
]}

 

10 hours ago, abunav said:

What I want is that the python script be executed upon a keyword trigger, and the JSON object thus generated in the script be used as list items in Alfred.

 

What you want is a Script Filter; that’s exactly what they’re for. Any other method will be a longer workaround.

Link to comment
  • vitor changed the title to [SOLVED] How can I list out options using an output from a Python script?

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...