Search results for

All search results
Best daily deals

Affiliate links on Android Authority may earn us a commission. Learn more.

How to use Tasker's Variable Split command - Android customization

Learning the Variable Split tool in Tasker may sound boring or scary, but it is a powerful tool, worth learning in our Android customization series.

Published onOctober 22, 2015

I hope you got to the bottom of the time card project we’ve been working on here on our Android customization series. The concepts and tools we covered are great pieces of Tasker that can be used for many may projects.

This week we are going to keep it really simple, we won’t even be building a project, we just want to look at how to use some of the more advanced Tasker variable tools.

Before we begin

I would tell you that you need to drop $2.99 on Tasker in the Google Play Store to follow along today, but if you are here, you probably already have it installed. With today’s piece, I presume you are working on a Tasker project and are looking for info on advanced variable management.

Variable Split

Let’s use that time card project as our starting point. Two weeks ago we created a variable called %WORKTIME,  which simply stored the amount of time between our starting and stopping point on the time card. %WORKTIME stored that time in seconds. We want to clean that up a bit today.

So, in short, today we will be taking the value of one variable, stored as 27590 seconds, manipulate it and output a much more friendly “7 hours, 39 minutes and 50 seconds.” Or 7:39:50, if you’d prefer.

Tasker Variable Split time

Disclaimer, we are looking to learn the Variable Split command today, which you do not actually need to solve these time conversions. Alternatively, you could just use straight math and create a new variable for each hours, minutes and remaining seconds. Also, I will be creating a new variable for each step of the way, this will extend the tutorial, but I hope it helps you to better see and practice each step of the project.

I’ll leave you to recap the previous project to get to this point, time card part 1 is right here, and part 2 is here. Also, I recommend duplicating the variable, instead of working on your live %WORKTIME variable, at least for now. Finally, I will create a brand new Task for this project, I presume you will eventually work the actions into your other Tasks.

In Tasker, head over to the Tasks tab to get started.

Start a new Task and give it an appropriate name, I’ll call mine “SecondsToTime“.

Action 1.

Tap the “+” button to add your first action.

(As mentioned, I would want to work on the side before implementing the changes below into a live project, so the first action is just a quick variable assignment to work from for today.)

Tasker Variable Split wt

Select Variables.

Select Variable Set.

Name: “%worktme“.

To: “27590“. Or any number you would like to work with.

Hit the system Back button to save and exit this task.

OK, now that we have a time value saved into a variable, let’s start tearing it down.

Action 2.

Tap the “+” button to add your next action. This action will create a new variable and perform the math to reduce the time in seconds down to time in hours.

Tasker Variable Split h

Select Variables.

Select Variable Set.

Name: “%worktmeH“. (“H” is for hours, keep that in mind when we do “M” and “S” for respective minutes and seconds later.)

To: “%worktme / 60 / 60“.

Turn on Do Maths.

Hit the system, Back button to save the action.

You’re good with the math up there, right? 27590 seconds = 7.663889 hours.

We are now finally about to learn the new concept, we want to basically extract the 7 from the number and save the rest for continued conversions.

Action 3.

Tap the “+” button to add a new action.

Tasker Variable Split sh

Select Variables.

Select Variable Split.

Name: “%worktmeH“.

Splitter:.” that’s just a decimal.

Hit the system Back button to save.

I’ll save you the research, what you’ve just done is create two new variables, the first is named %worktmeH1 and has a value of 7. The second is named %worktmeH2 and has value 663889.

Good work, we have our hours saved now, we just need to take that remaining value and do some more math. Remember that the new %worktmeH2 is actually 0.663889 hours, so we will have to convert that over to minutes now.

Action 4.

Hit the “+” button to add your next task. We are basically repeating the last action, just with the new numbers.

Tasker Variable Split m

Select Variables.

Select Variable Set.

Name: “%worktmeM“.

To: “0.%worktmeH2 * 60“. (That’s the number 0 at the beginning there.)

Turn on Do Maths.

Tap the system Back button to save.

Let’s look at that a little closer. We took our saved %worktmeH2 variable and turned it back into a decimal value by preceding it with “0.”. Then, with 0.663889 (hours) we multiply by 60 to get minutes. That’s 39.833333 minutes.

You know what comes next, we need to split that variable to get our full minutes value and the remaining decimal value.

Action 5.

Tap the “+” button to add the next action.

Tasker Variable Split sm

Select Variables.

Select Variable Split.

Name: “%worktmeM“.

Splitter: “.“.

Tap the system Back button to exit.

Just like before, we now have two new variables, the first, %workmeM1 has value 39 and the second, %worktmeM2 has value 833333.

Time to take that 833333 (minutes) and turn it in our remaining seconds.

Action 6.

Tap the “+” button to add this next action.

Tasker Variable Split s

Select Variables.

Select Variable Set.

Name: “%worktmeS“.

To: “0.%worktmeM2 * 60“.

Turn on Do Maths.

Hit that system Back button to save.

Walking through once again, we see that we turned 0.833333 minutes into 50.4 seconds.

If that is good enough for you, go ahead and pump it out to your other projects, or flash it to the display to see how it looks. Me, I’ll play the part of the perfectionist, I don’t want to see a fraction of a second there, let’s split that just one more time.

Action 7.

Tasker Variable Split ss

Select Variable, then select Variable Split. Name: “%worktmeS” and Splitter.“.

Woohoo, we did it. Let’s pump that out to the screen to see our results.

Action 8.

Tap the “+” button to add our last action for today.

Tasker Variable Split alert

Select Alert.

Select Flash.

Text: “%worktmeH1 hours, %worktmeM1 minutes and %worktmeS1 seconds.” (Alternatively, you can just put “%worktmeH1:%worktmeM1:%worktmeS1” to get the 7:39:50 format.)

Hit that system Back button and then hit the Task play button to see your work in action.

Tasker Variable Split Task

What’s next

Ignoring the repetition of our approach today, and how confusing the process may sound the first few times through it, I hope that you see how the Variable Split command works. The idea is pretty simple, looking at a variable that has a definite breaking point in it, this variable tool splits your value into multiple new variables at the breaking points.

We used the Variable Split tool to pull apart numbers, but you could pull apart variables filled with names, locations, or really anything. And your Splitter can be any character, or set of characters, that you desire. For example, you could reverse our work today, if you used the alternative output and saved it to a variable itself, use the Splitter “:” to get three variables with the hours, minutes and seconds saved in each.

Next week

I know our Android customization this week feels like it has no purpose, but I promise when you need the Variable Split, you’ll be happy for at least this rough idea of how to use it. Next week we will take Tasker to an entirely new level, it is beyond time that we took a look at Scenes. That is, creating completely new windows on your Android device.

Do you have a nifty project where you put the Variable Split tool in Tasker to good use?

You might like