AndroidApps

Quick Tasker tip: Comma separated values and arrays are good friends

Variables in Tasker are hard enough to grasp already, and then arrays show up to make it even harder. That’s a pity, since both are vital for being able to create a lot of powerful Tasker creations. When dealing with arrays, however, it’s important to know that comma separated values play nice with arrays.

One of the most common ways of creating arrays is to use Variable Split. Sometimes you can’t control what you have to split by to do this, but if you use Variable Split to turn something you yourself stored in a text file or something like that into an array, commas are good splitters. While they do have the disadvantage of being common enough to possibly be used in your values without being intended as splitters (e.g. commas as part of a sentence in a joke for a random joke system), the advantage of using commas is that you can instantly turn an array into a comma separated list of values by using the %arr() feature. In other words, you can move between an array and a comma separated list of values with a single command each way, which can be very helpful. I originally stored my todo list items on news lines of a text file, but eventually moved onto a comma separated list because of this.

The %arr() feature is also useful in that it makes arrays and variables with comma separated values interchangeable in several places in Tasker. I’ve previously talked about how it’s advisable to use single variables with comma separated values instead of actual arrays in Menu scene elements, because global arrays are slow. The Menu scene element gladly accepts a single variable with comma separated values and treats it more or less like an array, turning each value into a separate list item. Another example where the two work more or less the same are For loops, where you can either input an array in the %arr() form, or just a variable with a comma separated list of values.

varsereUsing both of these also gives you more tools for manipulating data. Having a single variable allows you to use Variable Search Replace, which can be used for things like removing or changing several different words in one go, without having to do one at a time. Arrays on the other hand can be used to for instance find, remove, or change a dynamic part of your data based on knowing a static part of it. I use these two features in combination in the task to add items to my todo list with AutoVoice, which means I use both arrays and single variables to handle the same data. I use the above mentioned array feature to locate the word immediately preceding the word “list” in the voice command, and then I move the data to a single variable in order to use Variable Search Replace to get rid of several “filler words” in one go.

append-variableSome of the tools available for these two methods are also very similar. Variable Search Replace can often be used instead of Variable Pop, and using Variable Set with the Append option checked and a comma before the content (e.g. Variable Set %list to ,%item) can be used instead of Variable Push to add something to the end of a list. You can also Variable Search Replace words with commas to for instance turn a command that uses “and” to separate items into an actual comma separated list of values, a trick that’s useful for voice control.

There are countless examples of where these two methods are similar, but the point I’m trying to get across is that it’s important to be aware of both methods and that they are in fact similar. It can be tempting to pick a method and stick to it, as it somehow feels cleaner, but using the two together can give you some advantages you might not have known were there.

tasker banner - for some reason we don't have an alt tag here

Pocketables does not accept targeted advertising, phony guest posts, paid reviews, etc. Help us keep this way with support on Patreon!
Become a patron at Patreon!

Andreas Ødegård

Andreas Ødegård is more interested in aftermarket (and user created) software and hardware than chasing the latest gadgets. His day job as a teacher keeps him interested in education tech and takes up most of his time.

Avatar of Andreas Ødegård