Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Termux:Task action executed asynchronously (i.e. doesn't make Tasker wait for it to finish) #16

Closed
ks9208661 opened this issue Oct 27, 2018 · 5 comments

Comments

@ks9208661
Copy link

I created a shell script in Termux that has the command "sleep 10" inside, and placed this in the ~/.termux/tasker directory. In Tasker, I created a Task with 2 actions. The first one is Termux:Task that executes the shell script. The second is a Flash action that simply pops up a window with an "Awake" message.

When I run the task, the second action immediately gets executed, without waiting for the first to finish.

I'm not sure if Termux:Task is meant to execute asynchronously or synchronously, i.e. whether this is a feature or a bug. I saw this Tasker guide on how to create plugins, and tried to read the source code to find out whether the synchronous settings are there or not. Unfortunately, things went way over my head very quickly, so I decided to open this issue instead.

I currently have a way around this asynchronous behaviour. In Tasker, I add an action right after the Termux:Task action that will make Tasker wait until a Tasker variable is set, before proceeding to the next action. Then on the Termux script level, I add a line at the end of my script which sets this Tasker variable using the technique I learned from glow's blog. It's a bit kludgy though, and I would rather do things natively in Termux, if I could only make Termux behave synchronously.

For all I know, asynchronicity is what other users want. I myself can imagine scenarios where that could be handy. Perhaps it would be nice to have a way, for example via a termux.properties global setting or a checkbox within the Termux:Task action, where the user can set whether Termux:Task should make Tasker wait for it to finish or not?

@jschwinger233
Copy link

jschwinger233 commented Nov 25, 2018

same issue, I am to make some 'meta programming' in Tasker, here's the steps:

  1. call termux:task to run a script that renders a xml file
  2. call import data to import rendered xml as a task
  3. call perform task for imported task

the problem is step 2 starts before step 1 finish, and I haven't got a elegant way to make it.

@dugite-code
Copy link

dugite-code commented Jul 24, 2019

For anyone looking for a work around Like I was using Installing the Termux API app you can issue intents back to Tasker. You will have to split your task up into chunks but it's the best I could come up with.

In a bash script

am broadcast --user 0 -a net.dinglish.tasker.totals -e totals "${calculated}"

In Tasker

Add a new profile: Event -> System Event -> Intent Received

Action: net.dinglish.tasker.totals

The variable %totals will be available in the task

@ks9208661
Copy link
Author

The 19 January 2020 update (0.4) may have finally brought us some form of synchronicity.

I deinstalled version 0.3 and installed 0.4. After that I ran a test. I have a script with the following lines:

sleep 5
echo Finished

In Tasker I created a task with 2 actions:

  1. Termux:Task action to run my script above, with the timeout setting to 30 seconds
  2. Flash %stdout

When I ran this task, it flashed Finished after 5 seconds.

Thanks Fredrik!!!

The phone I tested this on is rooted though. When I tried this in my other, unrooted phone, for some reason I'm getting an error. It runs the Termux action but waits the full 30 seconds, and then I get a an error (I see Termux: plugin comp: com.termux.tasker/com.termux.tasker.FireReceiver and some lines regarding add wait type, but the last line simply says Error: null). The settings for both phone, with the exception of one being rooted and the other one not, are the same (e.g. Termux and Termux:Task can auto-start, run in the background, do not care about battery, etc). I can overlook this issue for now since my rooted phone is the one I use for the stuff I'm doing, and things seem to work there.

@agnostic-apollo
Copy link
Member

@ks9208661 the wait type issue should be solved in version 0.5. Check number 9 in Issue 36 for details.

@agnostic-apollo
Copy link
Member

Check fecba50 for disabling wait for background commands. Other issues mentioned likely don't really apply anymore. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants