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

Alfred Workflow - How to pass multiple variables through Applescript to Output.

RayShines 2022. 4. 17. 13:37
반응형

I already posted about the same topic. But I realized that there is more simple solution to split an argument into several variables and pass them through Applescript to output and notification. This is the instruction.

 

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

 

Above link is more complicated solution. 

 

1. Split the Argument into Several 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.

 

alfred variable argument

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

 

And set the q, which means query for Alfred like above. The variables are conncted with &" "& just like the delimiter " ".

 

I don't know why exactly, you should set the c, the result of a*b, as text. If you don't, you can't set q starting with c. Of course, if you set the q starting with other than c, it would work. 


If the query was "3 7", then the new query would be "21 3 7". 

 

3. Split the Argument again.

The delimiter should be " " again, because the new query was set with " " in the middle. 

 

As I mentioned above, the new query is "21 3 7." 

 

If you split the query with delimiter " ", the result would be like below.

 

Split1 would be 21.

 

Split2 would be 3.

 

Split3 would be 7.

 

4. Pass the Variables into Output, as Notification.

alfred variable argument split pass to output

 

If you set the notification like above, the result would be like below.

 

alfred variable argument split pass to output

 

The query is 21 3 7. As you know 21 is the result of 3*7.

 

Split1 is 21, which is split from 21 3 7 as the first.

 

Split2 is 3, which is split from 21 3 7 as the second.

 

Split3 is 7, which is split from 21 3 6 as the third, the last.

 

And if you want, you can use split1, split2, split3 as variables with {var:split1}, {var:split2}, and {var:split3}.

 

 

alfred workflow variable argument split pass to output

 

I hope it helps.

 

반응형