TEL Launcher for Termux

repository·master·Indexed 41 days ago

https://github.com/t-e-l/tel

A specialized launcher designed for Termux experts to provide enhanced control and automation capabilities within the Termux environment.

Tokens
2.3K
Snippets
7
Records
8
Agent score
99%

What's inside TEL

  1. Overview of TEL (A launcher for Termux experts)

    master
    TEL is a launcher designed specifically for Termux experts. It provides a specialized interface or environment for managing and launching tasks within Termux. For detailed usage instructions, architectural concepts, and advanced configuration, users should refer to the official project wiki.
  2. Execute commands from third-party applications via RunCommandService

    master

    Termux allows third-party Android applications to execute commands or scripts by sending an Intent to the RunCommandService.

    Prerequisites

    1. Enable External Apps: In your Termux environment, you must set allow-external-apps to true in your termux.properties file (located at ~/.termux/termux.properties or ~/.config/termux/termux.properties).
    2. Permission: The calling application must declare the com.termux.permission.RUN_COMMAND permission and the user must grant it.
    3. Foreground/Background Behavior:
      • On Android 10+, if you want commands started with RUN_COMMAND_BACKGROUND set to false to automatically bring Termux to the foreground without manual notification interaction, Termux must be granted the 'draw over apps' permission.
      • To prevent Android from killing the service, it is recommended to disable battery optimizations for Termux.

    Intent Extras

    When sending the Intent, use the following keys:

    • com.termux.RUN_COMMAND_PATH (String, Required): The absolute path to the command or script. Supports $PREFIX/ and ~/ prefixes.
    • com.termux.RUN_COMMAND_ARGUMENTS (String[]): Optional arguments for the command.
    • com.termux.RUN_COMMAND_WORKDIR (String): Optional working directory. Defaults to Termux home. Supports $PREFIX/ and ~/ prefixes.
    • com.termux.RUN_COMMAND_BACKGROUND (Boolean): Whether to run in the background. Defaults to false.
    // Java example to run 'top -n 5' in Termux home
    Intent intent = new Intent();
    intent.setClassName("com.termux", "com.termux.app.RunCommandService");
    intent.setAction("com.termux.RUN_COMMAND");
    intent.putExtra("com.termux.RUN_COMMAND_PATH", "/data/data/com.termux/files/usr/bin/top");
    intent.putExtra("com.termux.RUN_COMMAND_ARGUMENTS", new String[]{"-n", "5"});
    intent.putExtra("com.termux.RUN_COMMAND_WORKDIR", "/data/data/com.termux/files/home");
    intent.putExtra("com.termux.RUN_COMMAND_BACKGROUND", false);
    startService(intent);
  3. Run commands via ADB/Shell using am startservice

    master

    You can trigger command execution from a shell environment (e.g., via ADB) using the am startservice command. This is useful for automation scripts interacting with the Termux service.

    Command Syntax

    am startservice --user 0 -n com.termux/com.termux.app.RunCommandService \
    -a com.termux.RUN_COMMAND \
    --es com.termux.RUN_COMMAND_PATH '/data/data/com.termux/files/usr/bin/top' \
    --esa com.termux.RUN_COMMAND_ARGUMENTS '-n,5' \
    --es com.termux.RUN_COMMAND_WORKDIR '/data/data/com.termux/files/home' \
    --ez com.termux.RUN_COMMAND_BACKGROUND 'false'

    Argument Mapping

    • --esa is used for the String array com.termux.RUN_COMMAND_ARGUMENTS (comma-separated values).
    • --es is used for String extras (PATH, WORKDIR).
    • --ez is used for the Boolean extra (BACKGROUND).
  4. Execute commands via TermuxService Intent actions

    master

    You can interact with the TermuxService using Android Intents. This allows external applications or system components to trigger specific actions within the Termux environment.

    Execute a command or session

    Use the com.termux.service_execute action to launch a new terminal session or a background task.

    • To launch a foreground session: Provide the executable path as the Intent data (URI). The service will create a new TerminalSession and launch TermuxActivity to display it.
    • To run in the background: Set the com.termux.execute.background extra to true. This creates a BackgroundJob instead of a visible session.

    Available Intent Extras

    Extra KeyTypeDescription
    com.termux.execute.argumentsString[]Arguments to pass to the executable.
    com.termux.execute.cwdStringThe current working directory for the execution.
    com.termux.execute.backgroundbooleanIf true, runs the command as a background task.

    Service Actions

    Action StringPurpose
    com.termux.service_executeLaunches a session or background job.
    com.termux.service_wake_lockAcquires a partial wake lock and a high-performance WiFi lock.
    com.termux.service_wake_unlockReleases both the wake lock and the WiFi lock.
    com.termux.service_stopFinishes all running terminal sessions and stops the service.
    // Example: Launching a background task via Intent
    Intent intent = new Intent("com.termux.service_execute");
    intent.setData(Uri.parse("/data/data/com.termux/files/usr/bin/top"));
    intent.putExtra("com.termux.execute.arguments", new String[]{"-b"});
    intent.putExtra("com.termux.execute.background", true);
    context.startService(intent);
  5. Reference: Termux Service Intent Actions

    master

    The following action strings are used to control the TermuxService lifecycle and power management via startService(Intent).

    private static final String ACTION_STOP_SERVICE = "com.termux.service_stop";
    private static final String ACTION_LOCK_WAKE = "com.termux.service_wake_lock";
    private static final String ACTION_UNLOCK_WAKE = "com.termux.service_wake_unlock";
    public static final String ACTION_EXECUTE = "com.termux.service_execute";
  6. Reference: RunCommandService Intent Extras

    master

    The following constants define the Intent extras used by com.termux.app.RunCommandService to configure command execution.

    public static final String RUN_COMMAND_ACTION = "com.termux.RUN_COMMAND";
    public static final String RUN_COMMAND_PATH = "com.termux.RUN_COMMAND_PATH";
    public static final String RUN_COMMAND_ARGUMENTS = "com.termux.RUN_COMMAND_ARGUMENTS";
    public static final String RUN_COMMAND_WORKDIR = "com.termux.RUN_COMMAND_WORKDIR";
    public static final String RUN_COMMAND_BACKGROUND = "com.termux.RUN_COMMAND_BACKGROUND";
  7. Reference: Termux Service Intent Extras

    master

    The following extra keys are used with the com.termux.service_execute action to configure the execution environment.

    public static final String EXTRA_ARGUMENTS = "com.termux.execute.arguments";
    public static final String EXTRA_CURRENT_WORKING_DIRECTORY = "com.termux.execute.cwd";
    public static final String EXTRA_EXECUTE_IN_BACKGROUND = "com.termux.execute.background";