Shell Variable Output Possible?

1,007 views
Skip to first unread message

Thomas Greene

unread,
Jun 12, 2013, 12:26:07 PM6/12/13
to tas...@googlegroups.com
I have about the shell with Tasker. The documentation for shell interaction doesn't cover this.

Is it possible to pull an attribute out of the shell?

What I'm doing is loop a while command set by a variable in Tasker. What I'd like to do is display the iteration it is on. I tried doing the store output in variable and put the variable in a display overlay but it only displays it the second time around, and ALL of the iterations. (1, 2, 3, 4, etc..)

The script for reference:

x=0; while [ $x -lt %TASKERINPUTVARIABLE ]; do input tap 111 111; input tap 111 111; input tap 111 111; ((x++)); echo $x; done

The echo $x was necessary to get the output but not necessary for functionality of what I want done.

So really what I'd like to do is take (%TASKERINPUTVARIABLE - current pass number) and store that as a variable I could use in a Tasker Overlay. Make sense? Possible?

TomL

unread,
Jun 12, 2013, 12:37:07 PM6/12/13
to tas...@googlegroups.com
I don't think you can have that kind of ongoing output from a shell script to Tasker via the shell output or shell result return variables.  Those are meant for end of execution, one time only output.

You can simplify your example to a shell script that counts 1 2 3, with sleeps inbetween the numbers.

echo 1; sleep 1; echo 2; sleep 2; echo 3

One way to try to do it would be to have your script append output to a file, and Tasker could watch that file in a loop.  It's not elegant, but it would work.

echo 1 >> /sdcard/output.txt; sleep 1; echo 2 >> /sdcard/output.txt; sleep 2; echo 3 >> /sdcard/output.txt

Tom

bdanders

unread,
Jun 12, 2013, 12:52:46 PM6/12/13
to tas...@googlegroups.com
I'd bet you could build and send an intent from the shell that would set a Tasker variable, but I wouldn't know where to start trying to figure that out.

bdanders

unread,
Jun 12, 2013, 2:15:31 PM6/12/13
to tas...@googlegroups.com
I haven't quite managed to set a variable from the shell, but the following line will run a named task ('Test Task' in this case), which you could use to iterate a variable.

am broadcast -a net.dinglisch.android.tasker.ACTION_TASK -e version_number '1.0' -e task_name 'Test Task' --ei task_priority 9

Thomas Greene

unread,
Jun 13, 2013, 10:02:49 AM6/13/13
to tas...@googlegroups.com
I like the idea outputting the file.. I was able to get it to write the file with the value by using the following script:

x=0; while [ $x -lt %TASKERINPUTVARIABLE ]; do input tap 111 111; input tap 111 111; input tap 111 111; ((x++)); echo $x > /sdcard/Android/data/com.app.app/app/file.txt; done

This shell action is running in a scene on a button tap. Prior to that, on the same button tap, an action is showing the overlay which I want to read from the file. How can I get it to display the text in the file as it changes??

Thomas Greene

unread,
Jun 14, 2013, 12:11:00 PM6/14/13
to tas...@googlegroups.com
Is there an option to 'live' show the contents of the file or am I not thinking about it properly?


On Wednesday, June 12, 2013 11:37:07 AM UTC-5, TomL wrote:

TomL

unread,
Jun 14, 2013, 12:34:21 PM6/14/13
to tas...@googlegroups.com
An option in what? Android OS? No.  A shell terminal?  Yeah, you could look in the commands "tail" or "less".  There should be an option that will force it to refresh and reread the file contents.

Tom

Tom Greene

unread,
Jun 14, 2013, 12:40:28 PM6/14/13
to tas...@googlegroups.com
What I meant was the overlay so I think you answered that.

I'm getting the output I want in the file but since it is loop in the shell.. should I may be busting each command out and doing the iteration in tasker instead of the shell?

Tom Greene


--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/grtnEWV3CW4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

TomL

unread,
Jun 14, 2013, 1:11:43 PM6/14/13
to tas...@googlegroups.com
You can try that.  But I think doing it that way will be slower, as Tasker has to: open a shell process, the shell runs one iteration, exit and tell shell it is done.  Shell has to exit and tell Tasker it is done.  And so on.

Tom

Tom Greene

unread,
Jun 14, 2013, 1:38:35 PM6/14/13
to tas...@googlegroups.com
I think I may investigate using intents from the shell then.. Thanks Tom!

Tom Greene

bdanders

unread,
Jun 14, 2013, 2:03:04 PM6/14/13
to tas...@googlegroups.com
For reference, the following is a Python script that will set a tasker variable. This is what I used to figure out how to run a task, but I still can't quite tell how to set a variable from the shell. Let us know if you figure that out.

-------------------------
import android
import time
import datetime
droid=android.Android()

class Task():
    SET_VARIABLE = 547
    def new_task(self):
        self.action_cnt = 0
        self.extras = {'version_number': '1.0', 'task_name': 'task' + str(time.time()), 'task_priority': 9 }
    def set_var(self, varname, value):
        self.action_cnt += 1
        self.extras['action' + str(self.action_cnt)] = {'action': self.SET_VARIABLE, 'arg:1': varname, 'arg:2': value, 'arg:3': False, 'arg:4': False, 'arg:5': False}
    def run_task(self):
        taskIntent = droid.makeIntent('net.dinglisch.android.tasker.ACTION_TASK', None, None, self.extras).result
        droid.sendBroadcastIntent(taskIntent)
    def set_var_now(self, varname, value):
        self.new_task()
        self.set_var(varname, value)
        self.run_task()

t = Task()
t.set_var_now("%My_Var", 'my value')
Reply all
Reply to author
Forward
0 new messages