erusev Posted March 4, 2023 Share Posted March 4, 2023 I'd like to pass a value from a "Run Script" object to a "Script Filter" object and use that value in the code the "Script Filter". How can I do that? Link to comment
vitor Posted March 4, 2023 Share Posted March 4, 2023 (edited) 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 March 4, 2023 by vitor erusev 1 Link to comment
erusev Posted March 4, 2023 Author Share Posted March 4, 2023 The value gets passed to the next object, the problem is, I don't know how to read it from the Script Filter. Here's a screenshot of what my Script Filter looks like inside. Link to comment
vitor Posted March 4, 2023 Share Posted March 4, 2023 (edited) 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 March 4, 2023 by vitor Link to comment
erusev Posted March 16, 2023 Author Share Posted March 16, 2023 Ok, I think what happens is that the output of the "Run Script" object gets passed to the "Script Filter" as input instead of an argument -- that is, the it becomes the text that shows in the input field. Link to comment
vitor Posted March 16, 2023 Share Posted March 16, 2023 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. erusev 1 Link to comment
erusev Posted March 16, 2023 Author Share Posted March 16, 2023 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? Link to comment
vitor Posted March 16, 2023 Share Posted March 16, 2023 1 hour ago, erusev said: Could it be because I have "Alfred filters results" checked? Correct. erusev 1 Link to comment
erusev Posted March 16, 2023 Author Share Posted March 16, 2023 Is there a naming conventions for vars that you intend to use as env vars? I imagine it'd be useful to distinguish them when "reading" the workflow. Link to comment
vitor Posted March 16, 2023 Share Posted March 16, 2023 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. erusev 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