IT 관련 팁/알프레드 워크플로우

Alfred Workflow - How to pass variables from Applescript to Output.

RayShines 2022. 4. 17. 09:49
반응형

Alfred workflow allows only one argument as query. You can split an argument into several variables with "Split Arg to Vars" utility of Alfred. Then, it was easy to pass the split variables to Applescript. However, it was tricky to pass the variables through Applescript to Output. This is the instruction.

1. How to split an argument into variables

You can split the argument with "Split Arg to Vars" utility of Alfred.


Then, I set the delimiter as " " for convenience like below, not just a blank. It is a space.

 

2. Write an Applescript for your own purpose.

You can write an Applescript like below.

You can see the "splitText(q, " "). " " is the delilmiter you set.

3. Set a new query by adding variables to an old query.

As I said above, Alfred workflow allows only one query. So It is not that easy pass multiple variables through the whole workflow. So I did like this.

Use "Args and Vars" utility.


And set the query like below.


The split variables from an argument were saved as split1, split2, and so on. And when you want to use the split variables, you can recall them with {var:split1}, {var:split2}, and so on.

So I set the new query as {query} {var:split1} {var:split2}. Make sure that you add a space between them, because you use a space as delimiter.

4. Split the argument again.

Then you split the argument into several variables again with "Split Arg and Vars" utility. The delimiter is also " " at this time, of course.

Then the result is like below.

the new split 1 : query
the new split 2 : the old split1
the new split 3 : the old spilt2

5. Then pass the variables to Output.

When you set the notification like below.

Now, test the workflow.


Then the result is like below.



The old argument, which is query, is "apple orange".

The old split1 is apple.

The old splt2 is orange.

And the query after Applescript is appleorange.

Then the argument is newly set.

The new argument, which is a new query, is appleorange apple orange, which is old query, old split1, old split2.

The new split 1 is appleorange.

The new split2 is apple.

The new split3 is orange.



It looks messy but it is working at least.

 

 

I posted a more simple solution. I Hope it helps.

Alfred Workflow - How to pass variables from Applescript to Output.

 

Alfred Workflow - How to pass variables from Applescript to Output.

Alfred workflow allows only one argument as query. You can split an argument into several variables with "Split Arg to Vars" utility of Alfred. Then, it was easy to pass the split variables to Apple..

rayshines.tistory.com

 

반응형