9

I've a OnePlus One with rooted Cyanogen OS 12 and Tasker v4.8. I've a bash script in PC which when exiting requires a Tasker's task to be executed. I've seen the question Running a tasker task via SSHDroid (or adb shell) and although the accepted answer didn't work on my Android, the solution is very simple. To call a task, do:

adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es "task_name" "TASK_NAME"   

However, that's all I can successfully do. During exit, my script needs to pass the exit status to task so that I can continue my processing on device based on script's result.

The official guide for invoking tasks is meant for programmers, so that didn't help me. Per the thread Launch Task via Intent I attempted various ways to pass a variable's value, but to no avail.

When we invoke a task from an another task, we're given the flexibility to pass values using two variables. Those two variables can be received by the invoked task using the name %par1 and %par2. In my demo task, all I'm doing is Alert → Flash → Text → Show me: %arg1 %par1.

# For demonstration only, I created a task named "lol"

adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es "task_name" "lol" --es "varNames" "par1" --es "varValues" "received"
adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es "task_name" "lol" --es "varNames" "%par1" --es "varValues" "received"
adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es "task_name" "lol" --es "varNames" "Par1" --es "varValues" "received"    # I also changed the variable name par1 to Par1 in task
adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es "task_name" "lol" --es "varNames" "%Par1" --es "varValues" "received"  

All those said commands execute with this output

Broadcasting: Intent { act=net.dinglisch.android.tasker.ACTION_TASK (has extras) }
Broadcast completed: result=0

Even sending this broadcast works

adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK -d "task:lol" --es "arg1" "received"  # I setup a profile to listen to this intent and receive extra from it in a task linked to profile

But calling the task directly and then sending the variable value doesn't do anything.

So, where is the fault in my approach and/or how do I send to and receive in a variable value in a task only using command-line?

Note that I'm not looking for a workaround. I'm perfectly able to come up with many workarounds to receive exit status from my script on device, but using intent appears to be the most straightforward solution of them and I want to learn this technique too.

Update

I raised my query at:

I received this reply from Pent, both through email and on forum

You would have to be able to add a StringArrayList extra to the adb call with -e, don't know if adb can do that.

If so, to see the format you can look TaskerIntent.java http://tasker.dinglisch.net/code/TaskerIntent.java, the function addLocalVariable, if you understand java.

And that is exactly what I later surmised after posting this question.

Per the answer here, I believe a string array can be passed using adb. So I attempted some queries but again met a dead end.

adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es "task_name" "lol" --es "varNames" '{"arg1"}' --es "varValues" '{"time"}'
adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es "task_name" "lol" --es "varNames" '{"par1"}' --es "varValues" '{"time"}'
adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es "task_name" "lol" --es "varNames" '{"par1"\,"arg1"}' --es "varValues" '{"received"\,"again"}'

I also converted the intent to URI using am to-intent-uri and tried sending the intent URI directly, with no success again.

New update

Based on the readings viz. 1, 2 and 3, I'm absolutely sure that a string array can be passed through adb shell am using --esa argument. Example:

adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --esa "par" "lol, cat"    # value lol goes in par1 variable and value cat goes in par2 variable

That said, this query still fails:

adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es task_name "lol" --esa varNames "arg1, par1" --esa varValues "lol, cat"

New update #2

You can use stock Android 6.0.1 as a testing ground.

  • I'm beginning to think that I need to pass string arrays and I've no idea how to proceed with that. – Firelord Jan 2 '16 at 0:28
  • Am not sure if reading this right, you have an adb script, when finished, has to pass off a variable to a task in tasker correct? But the task in tasker is not reciving this variable, and you want it to receive the variable. Am I on the correct track? – Matt07211 Jan 2 '16 at 2:43
  • It is a bash script, but yeah, at the end I want to call a task using adb and send a variable to it. – Firelord Jan 2 '16 at 2:46
  • Okay, will post any helpful info if I find any, and good luck – Matt07211 Jan 2 '16 at 2:47
  • Please excuse me if I sound stupid — because you are obviously more advanced in Tasker than me — but couldn't you simply make your script write the variable data to a text file before exit and then let Tasker read that file upon certain conditions and set the variables from it? – pure.by Jul 27 '16 at 16:02
1

Based on @firelord's findings and am's in-app document (output of am, no arg). This worked on my phone running 6.0.1:

$ su -c 'am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es task_name TASK_NAME --esal varNames %VAR_NAME1,%VAR_NAME2 --esal varValues VAR_VALUE1,VAR_VALUE2'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.