Run termux script using macrodroid
Running a Termux script from MacroDroid is best done using the Termux:Tasker plugin. Despite the name, this plugin works perfectly with MacroDroid.
Prerequisite: The "F-Droid" Rule
Critical: You must install both Termux and the Termux:Tasker plugin from F-Droid.
- If you installed Termux from the Google Play Store, it will not work because the Play Store version is outdated.
- Action: Uninstall the Play Store version and install the latest versions from F-Droid.
Step 1: Set up the Termux Environment
- Open Termux.
-
Create the mandatory folder for external scripts:
mkdir -p ~/.termux/tasker -
Move your script to this folder (or create a new one there).
- Example:
nano ~/.termux/tasker/myscript.sh
- Example:
-
Important: Make the script executable.
chmod +x ~/.termux/tasker/myscript.sh -
Ensure your script has the correct shebang:- Bash:
#!/data/data/com.termux/files/usr/bin/bash - Python:
#!/data/data/com.termux/files/usr/bin/python
- Bash:
Step 2: Grant Permissions
Android requires you to explicitly allow MacroDroid to run commands in Termux.
- Go to Android Settings → Apps → MacroDroid.
- Open Permissions.
- Allow: "Run commands in Termux environment".
Step 3: Create the MacroDroid Action
- Create a new Macro.
- Add a Trigger (e.g., Widget, Shake device, Time of day).
-
Add an Action:
- Applications → Tasker/Locale Plugin
- Select Termux:Tasker
- Tap again to configure
-
In the Termux:Tasker configuration:
- Executable: Select your script from
~/.termux/tasker. - Arguments: Add arguments (optional).
- In Terminal: Check to view terminal output; uncheck to run silently.
- Executable: Select your script from
- Save and test the macro.
Troubleshooting
| Issue | Solution |
|---|---|
| "Permission Denied" | You likely forgot chmod +x filename.sh. |
| "File not found" | Ensure the script is inside ~/.termux/tasker/. |
| Script runs but fails | Fix the shebang using: termux-fix-shebang filename.sh. |
| Plugin List is Empty | Restart MacroDroid & Termux. Verify the folder exists. |
Comments
Post a Comment