Taki Posted August 8, 2020 Share Posted August 8, 2020 (edited) Hi All, I have a set of snippets which can work across different projects, like !foo -> "cd /home/{var:PROJECT}/foo" !bar-> "tail /home/{var:PROJECT}/bar/abc.log" !baz-> "sudo /home/{var:PROJECT}/baz" I need to use the variable "PROJECT" to avoid the repetition of creation similar snippets for different projects. And I want to use PROJECT like a global variable. Once I set the current PROJECT, all the snippets can be automatically expanded. I tried to create a separate workflow, which accepts args and save the arg to variable PROJECT. When I enter "Set PROJECT ABC" in Alfred, it will pass the arg ABC to the variable PROJECT. But it seems the value of the variable isn't used in the snippet expansion. When I type !foo, the variable isn't replaced by ABC. The only workaround I can think of is to use a clipboard. Are there any other ways? Edited August 8, 2020 by Taki Link to comment
deanishe Posted August 8, 2020 Share Posted August 8, 2020 1 hour ago, Taki said: But it seems the value of the variable isn't used in the snippet expansion. That is possible, so you must be doing it wrong. Post a link to your workflow, so we can actually see what you’re talking about. Link to comment
Taki Posted August 8, 2020 Author Share Posted August 8, 2020 (edited) 16 minutes ago, deanishe said: That is possible, so you must be doing it wrong. Post a link to your workflow, so we can actually see what you’re talking about. Hi @deanishe Sorry I don't know how to share the workflow yet. But the workflow just contains two components Keyword -------> Arg & Vars Inside the "Arg & Vars", it set Variable Name PROJECT to value {query}. The snippets are separate from the workflow, under the "Features" tab. Edited August 8, 2020 by Taki Link to comment
deanishe Posted August 8, 2020 Share Posted August 8, 2020 35 minutes ago, Taki said: The snippets are separate from the workflow, under the "Features" tab. It doesn't work that way. Variables are only valid in the workflow they're set in. Any variables set while a workflow is running cease to exist when the workflow stops running. To use variables in snippets, you must use a Snippet Trigger to implement them in a workflow. Link to comment
Taki Posted August 8, 2020 Author Share Posted August 8, 2020 10 minutes ago, deanishe said: It doesn't work that way. Variables are only valid in the workflow they're set in. Any variables set while a workflow is running cease to exist when the workflow stops running. To use variables in snippets, you must use a Snippet Trigger to implement them in a workflow. Thank you very much! I have found a workaround by directly exporting the PROJECT env variable to the shell and use env variables instead of Alfred variables. 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