Android and Linux

Monday, January 3, 2011

Tasker variable select function

I had a task where I wanted to be able to enter a custom number into a variable. Tasker has a "variable Query" action that pops up a box and allows you to type in the variable, but I didn't like it because you have to tap on the box to bring up the keyboard, type out the entry, then save it. But a workaround is simple, as long as you know certain values the variable could be.

Task: VarMenu1
1 Variable Set %VAR to EOF (you could use 'variable clear' but I prefer using EOF since errors will sometimes manifest as EOF)
2 Perform Task VarMenu2
3 Wait Until %VAR doesn't match EOF

Task: VarMenu2
Task Type: Menu
1 Set Variable %VAR to 0
2 Set Variable %VAR to 1
3 Set Variable %VAR to 2
4 Set Variable %VAR to 3
...etc (change numbers to suit your needs)

Used alone, VarMenu1 acts like a function or library, a piece of code that you can leave by itself and call any time you need to perform a certain task, in this case custom setting a variable. Any time you're writing a task that requires you to input a custom value for a variable, just put "Perform Task: VarMenu1" and your task will pause to allow you to select a value from a list.

You can also use variables for task names when using the "Perform Task" action. This would be useful if you want to prepare more than one menu of variables. Instead of 0,1,2,3, maybe you also want to have a menu for 0,5,10,20. Just make a new menu task containing those numbers, let's call it VarMenu3, change the "Perform Task" in VarMenu1 to a variable and set the variable before that step.

1 Variable Set %VAR to EOF
2 Variable Set %VARMENU to VarMenu3
3 Perform Task %VARMENU
4 Wait Until %VAR doesn't match EOF

Voila, flexibility!