Android and Linux

Sunday, January 16, 2011

Tasker command runner

The Locale Execute Plugin is great for running shell commands or scripts with Tasker, but it can be tedious when you're testing the commands. It takes several steps to edit tasks themselves, and even if you don't need to edit the task, you still have to get to the editing error to change the command in the plugin.

There is a way to make it easier.

Profile/Context : Variable Set. Variable %COMMAND

Task:
1- Write File /sdcard/command %COMMAND
2- Execute: sh /sdcard/command

Or if you'd like to get the output of the command:

Task:
1- Write File /sdcard/output WAIT
2- Write File /sdcard/command %COMMAND
3- Execute: sh /sdcard/command
4- Read Paragraph: /sdcard/output to %OUTPUT
5- Go To 4 if %OUTPUT matches WAIT
6- Flash %OUTPUT if %OUTPUT doesn't match EOF
7- Variable Clear %COMMAND

Just make sure your command sends it's output to that file.

Now you only need to set the variable %COMMAND with the actual command you want to use. When the variable is set, Tasker will write the command into the file and the plugin will execute it.

You could even set the command by popping up a list to choose from, or by using the Variable Query which allows you to type a variable's contents into a box.

Security:

I wouldn't consider it very safe to have a file in which commands can be entered by anyone and ran, possibly with root permissions. But the first step of the task is to overwrite the file, so I suppose a person would have to be able to control Tasker in order to get their code executed, and if they can do that, they already have free reign anyway, so it's probably fairly safe.

Followers