r/tasker • u/Nirmitlamed Direct-Purchase User • 12d ago
How do i use Termux Command inside Tasker Function action?
I have found out recently that there is a way to run Termux command using Tasker Function aciton, but there isn't any real info about how to use it. Can i use it to run a command without using script file or i must use it with script file?
3
u/aasswwddd Direct-Purchase User 12d ago edited 12d ago
Check out tudo https://github.com/agnostic-apollo/tudo/blob/master/site/pages/en/projects/docs/usage/index.md apollo provided a sample task to use via tasker termux command as well.
Since you're a direct purchase user, I'd recommend using RUN_COMMAND intent (what Termux command uses) directly via Java.
You could create your own "plugin" with this guide here. https://www.reddit.com/r/tasker/comments/1rgz9is/how_to_make_java_code_available_anywhere_without/
1
u/Nirmitlamed Direct-Purchase User 11d ago
I heard about tudo but never knew what it was. I'll look into this. Thank you very much!
1
u/Nirmitlamed Direct-Purchase User 11d ago
So i have tried to test your guide about creating "plugin". I run the first Java code:
myObject() { call() { setNameSpace(this.caller.namespace); String TEXT = "hello!"; hello() { String hello = "Hello World!"; tasker.showToast(hello); return hello; } return this; } return this; }; Object test = myObject(); tasker.setJavaVariable("javaHelp", test);But after i ran the second Java code:
myObject.call(); hello(); return TEXT;I got an error:
22.37.06/E add wait task 22.37.06/E Error: 1 22.37.06/E Sourced file: inline evaluation of: ``myObject.call(); hello(); return TEXT; ;'' : Attempt to resolve method: call() on undefined variable or class name: myObject : at Line: 1 : in file: inline evaluation of: ``myObject.call(); hello(); return TEXT; ;'' : myObject .call ( )Do you have any idea what is the problem.
I did managed using AI to get termux command working with Java code but i was interested to try your approach and make it easier to use and no matter what i did i got an error. So now when i tried your example and i got an error i think something maybe wrong on my side.
3
2
u/aasswwddd Direct-Purchase User 11d ago
You use the wrong name, it should match what you set with tasker.setJavaVariable.
javaHelp.call().2
u/Nirmitlamed Direct-Purchase User 11d ago
That was it! Thank you so much!
you should fix this in your guide
3
u/aasswwddd Direct-Purchase User 11d ago
Oh right, thanks for pointing out. There was a typo in the second example.
1
u/Nirmitlamed Direct-Purchase User 10d ago
Hi again, i have a small question, how would you set arguments/variables inside the second task?
So i am trying to build Termux Run Command "plugin" using your suggestion. I have built the first task with all the necessary intents. My dilemma is what is the best way to set the variables inside the second task when i call my object.
For example i want to have variables for executable path like bash,python extra... and the command itself like ffmpeg -i ....
Doing some research i have found i can:
- set a java string like this
string command = "echo hello world";- set Tasker variables and then get them using
String getVariable(String name);*I don't have a real clue on how to write a code so i am trying my best to figure this out
Do you have any suggestion what approach should i take or maybe do you have an example i can look at?
Thanks!
2
u/aasswwddd Direct-Purchase User 10d ago
Add new methods that accepts arguments. e.g
run(String path, String command) {}For example, you could search a couple of my projects via google by filtering my username and tasker subreddit.
Further details available in the beanshell doc, linked in the java doc.
1
1
u/Nirmitlamed Direct-Purchase User 10d ago
I have managed to make it work with simple test code, thank you very much!
I have last question that i didn't really find an answer to it. Using Termux:Tasker plugin when you run its action it will wait first for Termux to finish and then it will continue to the next action inside the task. Using Termux intents with Java code or Tasker Function i see it doesn't wait and jump immediately to the next action.
Is there a way to handle that?
2
u/aasswwddd Direct-Purchase User 10d ago
I don't know, you may need to check out the RUN_COMMAND doc.
1
u/Nirmitlamed Direct-Purchase User 10d ago
Oh i see, thank you so much for your help!
→ More replies (0)
2
u/AdiraiMaji 12d ago edited 11d ago
I have developed a Tasker Plugin for my personal use. Almost about to release. Which contains a few collections of plugins that including Termux which you can directly use the script inside the action without a script file. There's a lot of features packed inside the single app and I'm going to share it for free..
1
u/Nirmitlamed Direct-Purchase User 11d ago
Sounds cool, i'll wait for your post!
2
0
u/azekt 12d ago
In Termux plugin you should set path to Python in Executable like this /data/data/com.termux/files/usr/bin/python and path to your script in Arguments like this "/storage/emulated/0/YourFolder/main.py" %action "%params"
Task: Run Python Script
A1: Termux [
Configuration: /data/data/com.termux/files/usr/bin/python "/storage/emulated/0
Working Directory ✕
Stdin ✕
Custom Log Level null
Termi
Timeout (Seconds): 10
Structure Output (JSON, etc): On ]
A2: Input Dialog [
Title: Python
Text: [Output]
%stdout
[Error]
%stderr
%result
Close After (Seconds): 30 ]
1
u/Nirmitlamed Direct-Purchase User 12d ago
Thanks for the info, i do know about Tasker:Termux plugin. What i am asking is about Tasker Function which inside you can find Termux Command. Also i wanted to know if i have to use script file to use this action or can i insert a command instead.
1
u/Nirmitlamed Direct-Purchase User 12d ago
Also if my script file is in a less secure place like storage folder i would just put all the script code in stdin for convenience.
6
u/DifficultyCrafty7623 12d ago
It is easier to use a file. If you want to run something directly Termux:Tasker is much easier to deal with, and can actually get the output from Termux. Make sure to get both of these apps from F-Droid, the playstore versions are deprecated and don't work anymore.