Jump to content

Variable Placeholder in Snippets


Recommended Posts

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 by Taki
Link to comment
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.

image.thumb.png.8cf195dc9313ac20e37c70d2ee324a0b.png

 

Edited by Taki
Link to comment
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
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

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