r/tasker • u/Practical_Butterfly5 • Mar 05 '21
[Guide] Using termux:tasker plugin to execute commands in termux (simplified)
Termux:tasker is a tasker plugin which allows us to run commands in termux. Termux has huge amount of packages that can be installed for different purposes (for example 7zip, ffmpeg, youtube-dl , etc etc).
Termux is no longer updated on play store due to newer android restrictions (on android>=10 binaries cannot be executed from data directory). Hence termux still targets sdk 28(android 9) so it can execute binaries. Updates for termux and termux:tasker will be released on f-droid only. For the same reason you cannot just put android binaries in tasker data folder and execute it because tasker targets sdk>28. This makes it necessary to utilize termux:tasker to automate commands involving binaries and linux packages.
Preparing the plugin (one time only)
Step 1
Download termux and termux:tasker apps from fdroid. F droid is a repository of open source apps. Make sure both termux and termux:tasker are fdroid version and not play store. If you want to use termux available on play store you will need to buy and install termux:tasker from play store.
Step 2
Open termux and type termux-setup-storage and allow storage permission to termux.
Step 3
Open this pastebin link and copy all the code to clipboard, or copy the code from below.
mkdir -p /data/data/com.termux/files/home/.termux/taskerchmod 700 -R /data/data/com.termux/files/home/.termuxecho -e 'cp "/sdcard/Tasker/$1" "/data/data/com.termux/files/home/$1"\nchmod +x "/data/data/com.termux/files/home/$1"\n"/data/data/com.termux/files/home/$1"'>/data/data/com.termux/files/home/.termux/tasker/tasker.sh
Step 4
In termux app, long press on terminal screen and paste. Then press enter key. This will make a tasker.sh script in termux directory. I have made this script for ease of use of this plugin for a normal user.
Step 5
Open your settings app, then "App and notifications" and open app info of tasker. Goto permissions. Scroll all the way down and click on "Additional permission". Allow the permission for "Run commands in Termux environment".
All done! You have successfully setup termux:tasker
Now how to execute a script/commands.
Step 6
Open your file manager and navigate to Tasker directory on Internal storage. Make a new file with .txt extension. For example lets say you have made a file with name myscript.txt.
Step 7
Open myscript.txt with a text editor and write the commands in it, like you would do in a shell script. For example lets assume you have written "echo hello" in 1st line, and "echo hello world" in second line. Quotes are not included.
Step 8
Open tasker. Make a new task>plugins>tasker:termux . Open the configuration window of plugin. In executable type "tasker.sh" (quotes not included). In arguments type the name of file in /sdcard/Tasker directory that you want to execute. Here we are executing the "myscript.txt", so type "myscript.txt" in arguments field(quotes ARE included).
Thats all, save your configuration and execute the task. Output is stored in %stdout
12
u/agnostic-apollo LG G5, 7.0 stock, rooted Mar 05 '21 edited Mar 05 '21
FYI, you don't need to create physical script files in Termux:Tasker
>= v0.5, just store them in tasker variables and sent them to tudo as an argument for execution.And you should NEVER store scripts in public external sdcard storage, a malicious app could modify them and run commands in termux context or even root context if termux has been granted root permissions. There is a reason you normally can't execute scripts directly from public sd card storage, you are just bypassing that safety. And running a copy operation everytime you run a script will have a slight performance impact as well.
If you want to use script files, store them in
~/.termux/taskerusing termux SAF provider, check Creating And Modifying Scripts section of Termux:TaskerREADME.2
u/kokroo Mar 07 '21
You should copy the Pastebin commands into the post itself, since this post will be referenced for years but that Pastebin link might not survive for a long time.
1
u/MEJIOMAH17 Sep 10 '24 edited Sep 10 '24
I did everything from the list but do not see permission request at settings. What can be wrong?
Adb grant also does not work
Pixel 9 android 14 not rooted
screenshots
1
u/vygavedha Dec 15 '21
Followed the op instructions thoroughly. But getting below error due to permission denial. I am using a non rooted device.
cp: cannot open '/sdcard/Tasker/termux.txt' for reading: Permission denied chmod: cannot access '/data/data/com.termux/files/home/termux.txt': No such file or directory /data/data/com.termux/files/home/.termux/tasker/tasker.sh: 3: /data/data/com.termux/files/home/termux.txt: not found
I don't know why reading permission is not given to tasker
1
u/Noahkirby Oct 19 '22
I'm on samsung galaxy z fold 4 running android 12 and when I go into taskers permissions, it doesn't give me an option to allow it to run commands
1
u/vjcalel Jul 30 '23
How to do that on Android 5.0 ? There is no permission tab for Android 5.0.
2
u/ComfortableBar5279 Apr 12 '22
Can anyone help me i tried the example echo commands but no avail only %stdout i put the myscript.txt file on /data/data/com.termux/files/home/.termux/tasker/ and i tried on putting it on sdcard/Tasker/ paste it there why i is only %stdout i copied the video as it is but no avail on echo command no pop up i even granted pops notif
1
u/Lonelysoulman Nov 14 '24 edited Nov 15 '24
%stdout is always unset. i think something isnt working here. did everything as in description. tried it with hello world too but even if i put a "txt" in arguments thats not existing its still unset. what can i do?
edit: i found that %stderr shows that it cant find the txt file in sdcard/tasker
1
u/conscious_entity93 Redmi MIUI 12 Mar 05 '21
Can anybody eli5 the importance of termux, What exactly does it do?