r/tasker • u/Ratchet_Guy Moderator • Nov 26 '23
How To - Project Share [How To] - Assign Multiple Variable Names and Values in a Single Line Format!
Sometimes in Tasker you just want to set a whole bunch of variables and their values at one time in a very simple format.
Now yes I know there is the "Multiple Variable Set" Action, but - that sticks all the variable names in one text field, and all the related values in another field below it. That creates a number of issues both in quickly defining variables and in quickly changing them.
For example take this image of some color-related variable names and their related hex values using the existing "Multiple Variables Set" Action. Let's say you quickly want to change the "highlight" color value. Can you quickly/easily correlate its value/position in the bottom text field in that image?
Sometimes its much easier to have the name/value pairs on the same line like this or some other simple data like this. I may have posted this before somewhere but I figured I'd post it again here just in case. Thanks to some quick little javascript by /u/JustRollWithIt - variable name/value pairs can be quickly configured on the same line in the format shown in the images above:
varname=value
varname=value
varname=value
etc
So use just one "Variable Set" Action to put that data in a variable named %data then run the following Javascriptlet in the next Action. Don't worry, the single Action of code is in the Taskernet Download.
Taskernet Download The Code/Example
And that's it! You've got all the variables you want quickly assigned with their values on single lines. Now, I'm sure there's a thousand technical quirks with certain characters in the data and all kinds of little stuff, but this is made just to be a quick/simple way to assign variables using basic simple data
Hope this helps some folks out!
4
u/wioneo Nov 26 '23
I believe you could also just do everything with one Javascriptlet action, e.g.
3
u/Bushido--- Nov 26 '23
As the previous writer said, this is also possible with Javascriptlet. You can then simply use %color in Tasker, for example, or local("color"); in other JavaScriptlets.
2
u/bernabap Nov 27 '23
I like the idea but I think it's easier to use the Perform Task action that makes the single Javascriptlet action irrelevant to process the data. This way you actually use only one single action to create multiple variables in the tasks that is easily accessible.
I made two tasks, one to convert the data to multiple variables and the other to a JSON variable. Link
1
u/EdwardBackstrom I Probably Screwed It Up Feb 06 '25
Not too far gone to be necro posting. I've played around with this idea for some multi variable 'subroutines' I've been building via Perform Task, %par1, %par2, and all those headaches. I tried to get the scriptlet to deconstruct %par2 directly into the various variables but it does not seem to do anything. It will work if I set %data to %par2 first which is how it is designed. How can I modify this to make it work without the intermediate Variable Set?
edit: added percent signs for consistency.
1
u/UnkleMike Nov 26 '23
You could also just use Tasker's Multiple Variable Set action. I don't particularly like the input format of the built-in action (variable names in one field, values in another), but it exists, and might be less off-putting for someone with no exposure to Javascriplets.
1
u/supremindset Nov 27 '23
A trick that really helps and makes things easier for all of us. However, I have one question. How do I do it on a global variable?
Can you show me how?
2
u/x-mrrobot-x Nov 28 '23 edited Nov 28 '23
This type of thing is quite useful, I use something similar to define variables from json, it would be interesting to add an example task for this use case too. example:
In the task there would be a variable %json_data with this value:
And in the javascriptlet action something like this:
or
This method I mentioned above would be useful for Http Request action responses or Http Request Event triggers.