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

  1. Open Termux.
  2. Create the mandatory folder for external scripts:
    mkdir -p ~/.termux/tasker
  3. Move your script to this folder (or create a new one there).
    • Example: nano ~/.termux/tasker/myscript.sh
  4. Important: Make the script executable.
    chmod +x ~/.termux/tasker/myscript.sh
  5. 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

Step 2: Grant Permissions

Android requires you to explicitly allow MacroDroid to run commands in Termux.

  1. Go to Android SettingsAppsMacroDroid.
  2. Open Permissions.
  3. Allow: "Run commands in Termux environment".

Step 3: Create the MacroDroid Action

  1. Create a new Macro.
  2. Add a Trigger (e.g., Widget, Shake device, Time of day).
  3. Add an Action:
    • Applications → Tasker/Locale Plugin
    • Select Termux:Tasker
    • Tap again to configure
  4. 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.
  5. 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

Popular posts from this blog

Useful aliases

Enable Search Engine Friendly (Pretty URLs) in Yii2