29
Completed

Create a variable whose value is the name of the current task.

Please provide a way to get the name of the currently running task (and only that task). This would allow tasks to push themselves on to a stack and have other tasks pop off the stack and execute those tasks (eg to set and reset volume profiles).

10 replies

This is now available with the Test Tasker > Current Task Name action :)

IMO this is a better solution for such a small use case.

I'm sorry Robert, but I have already said that it could be done only with two actions and that the predefined local variables can be overwritten.

 sTaskName
A1: Variable Search Replace
Variable:%caller1
Search:task=(\w+)
Replace Matches:On
Replace With:$1
A2: Return
Value:%caller1
Stop:On

And it can be used like this ...

Test
A1: Perform Task
Name: sTaskName
Priority: %priority
Return Value Variable: %task
Stop: Off
A2: Flash
Text: %task
Long: Off

Even with the simplest "trick" three actions are necessary. Don't you think it would be better to have a variable that provides the information immediately?

RR

It is simple to write a function returning the current task's name:

        Get Task Name
        
    A1: Variable Set 
        Name: %path 
        To: %caller(1) 
        Recurse Variables: Off 
        Do Maths: Off 
        Append: Off 
        Max Rounding Digits: 3 
        
    A2: Variable Split 
        Name: %path 
        Splitter: = 
        Delete Base: Off 
        
    A3: Return 
        Value: %path(2) 
        Stop: On 

Now ithe current task's name can be returned when needed with a single statement:

        Test
        
    A1: Perform Task 
        Name: Get Task Name 
        Priority: %priority 
        Return Value Variable: %this_taskname 
        Stop: Off 
        
    A2: Flash 
        Text: %this_taskname 
        Long: Off 

IMO this is a better solution for such a small use case.

I am using a subtask to get the task name. It would be so much easier to have a preset variable.

Why are you so much against it Robert?

RR

I am not agaist it, per se. It's just completely unnecessary.

If the developer wants to put it in, then fine. But I won't upvote it.

The predefined local variables (%err, %errmsg, %priority, %qtime, %par and %caller) can be changed by the user without problems (not like the predefined global variables). I think it is a minor problem that Tasker defines the %task variable with the name of the task and that the user already used it in his project.

BB

This can be achieved by showing a scene, %caller1 will be set to the name of the Task afterwards.

The goal is not to use an alternative solution. The objective is that the name of the task be provided directly by Tasker.

And if you want to use an alternative solution, I think a task with two actions is better than a scene.

TP

I just came across this the other day where I really needed the name of the Task available as a variable inside the Task itself.

Since we've already got: %err, %errmsg, %priority, %qtime, and %caller - it makes perfect sense to have a local of something like %taskname.

The only issue being if the name chosen is already in use by people in their existing Tasks all over the place.

Then I saw Rich D's idea here and think that is the PERFECT WAY to do this. Just add it to "Test Tasker" as "Name of this Task" :) 

For me, it would make sense to have a %task variable in a similar way as the %caller1 and %caller2 variables. The only difference is that it would only contain the task name.

NY

I don't know about `%LASTTASK` but the name of the current task isn't limited to testing/debugging only.

SD

I also like the idea of %LASTTASK. This would be handy if a rogue Task were causing an unexpected issue.  These variable could be used to troubleshoot or have other uses. 

RD

I would think the best place for this would be in the 'Test Tasker' action. 

TP

This is most definitely the best solution for this. Adding a new local variable name (to the existing %qtime, %caller, etc) runs into the problem of people all over the place who happen to be using the newly chosen variable for something in their existing Tasks already.

To make it into a manual action, with an output variable needing to be chosen by the user - solves that problem completely. Great idea!!