Jump to content

Is there a way to use Script Filter -> Run Script -> Run Script ... as a chain?


Recommended Posts

Hi, I am an experienced Python-er, but new to Alfred Workflow development.

 

I am wondering,  is it possible to achieve things like this:

 

Suppose I have a series of chained objects: Script Filter -> Run Script -> Run Script ...:

image.png.8d0b6e7de7e3047465a74dafdbf544fd.png

 

From what I understand, (1) By using Python, I need to create a formatted json data (described here), send it to stdin, Alfred will render it and displays the results on the screen; (2) Alfred can pass arguments from one object to anther, by using the `arg` arguemnt contained in each result's json object.  The value of `arg` will be treated as the input of the next chained object.

 

What I expect to achieve is: 

  1. Accept a keyword to trigger the first Script Filter, it triggers a Python script and generates a list of results as feedbacks, Alfred displays these results on the screen, line by line.
  2. User selects one of the result, Alfred then passes its corresponded arg property to the next chained Run Script (the value of arg will be its input).
  3. Run an another Python script in the Run Script and it generates a new list of results as new feedbacks.
  4. Alfred wil display the new results on the screen, but I failed.

 

What I expected here is Alfred will clear the old feedbacks generated in Script Filter and display new feedbacks generated in the Run Script. Then user can select one of the new results and pass it to the next next chained Run Script. Endless.

 

But when I try to program it, Alfred failed to clear the old ones, the Alfred window just disappered. Is it normal?

 

Many many thanks! 

Link to comment

Run Scripts run code, they don’t display results. Also, they don’t use the same JSON format and can just pass what’s sent to STDOUT. I recommend reading the documentation pages on both.

 

In addition, open the debugger to follow the flow of arguments.

 

If you want to list results again, you’ll need to pass them to another Script Filter so they can be interpreted. Because your STDOUT will be used in the input field, you’ll likely need an Arg and Vars Utility to empty the argument and save it to a variable, which you’ll then read back in the script.

Link to comment
2 hours ago, vitor said:

Run Scripts run code, they don’t display results. Also, they don’t use the same JSON format and can just pass what’s sent to STDOUT. I recommend reading the documentation pages on both.

 

In addition, open the debugger to follow the flow of arguments.

 

If you want to list results again, you’ll need to pass them to another Script Filter so they can be interpreted. Because your STDOUT will be used in the input field, you’ll likely need an Arg and Vars Utility to empty the argument and save it to a variable, which you’ll then read back in the script.

Thanks for the detailed explanation!

 

I always thought Run Script and Script Filter were the same, just missing the keyword part. 

 

Problem solved.

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