Jump to content

How to pass a value from a previous object to a Script Filter


Recommended Posts

Send your text to Standard Output. The specifics are down to the language and what you’re doing, e.g. echo 'YOUR TEXT' in ZSH or puts 'YOUR TEXT' in Ruby. With both AppleScript and JXA you can just have a string on its own line, or return "YOUR TEXT" (in JXA you need the function run() because you cannot return outside of functions).

 

The Script Filter will then get that as an argument.

 

Imagine each of those objects is a command in the terminal, and the connections are pipes. The logic is similar.

 

Edited by vitor
Link to comment
40 minutes ago, erusev said:

I don't know how to read it from the Script Filter.

 

Again, it’s an argument. Do the same thing as if you were receiving an argument given to your script in a terminal. Change the Language dropdown and the Script box will show an example in each language.


For Deno it is likely Deno.args[0].

 

Edited by vitor
Link to comment
  • 2 weeks later...
20 minutes ago, erusev said:

that is, the it becomes the text that shows in the input field.


Which in turn is used as the argument.

 

If you want to have the value from the Run Script and use a different argument for filtering, save the former as a variable and read it from the script as an environment variable.


If that still doesn’t get you what you’re after, please share your workflow and explain exactly what you want, as otherwise this is looking like an XY problem.

Link to comment

It worked!

 

I had no idea alfred vars are available as env vars.

 

> Which in turn is used as the argument.

 

Well, it becomes the search input, and is not an arg I can read from the script.

 

Could it be because I have "Alfred filters results" checked?

 

CleanShot2023-03-16at13_21.48@2x.png.10682ecc154edb468eabf0278ed7e0c8.png

Link to comment

No need to overthink the name. If you define them during the workflow’s run (e.g. in a Arg and Vars) they only live until the end of said run and don’t affect the workflow as a whole. Name them as you would if setting them in a Terminal for the duration of that session. Avoid alfred_ as a prefix to not accidentally overwrite any that exist. Also don’t overwrite important variables you’d also find in a default shell session (e.g. PATH) unless you’re really sure that’s what you want.

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