u/Nirmitlamed

▲ 6 r/tasker

Project Sharing: Generate Tasker Task from XML using Java Code

For another project of mine, I thought it would be really useful if I could automatically create a Task when needed. After some trial and error, I found a solution using the Java Code action.

In short, what does this Java Code do?

It takes the XML code of a complete Task or Project, compresses it directly in memory using GZIP (no temporary file is created), converts it to Base64, and creates a Tasker Data URI like:

taskertask://...
or
taskerproject://...

The URI is then opened, allowing Tasker to ask the user if they want to import the Task.

With the help of an AI assistant, I created a robust version that is also relatively easy to customize for your own projects.

To Import Taskernet Project: Click Here
Java Code: paste.to/?430b135723f91cae#4SXMosAyPGR9Yxty95WgM7g8JZxHzNGNYsqvDtzA2cEN

How to use it

First, create a Task containing the actions you want.

For this example, let's say we have a Task called "Task Example" with a Flash action containing the text "Text".

The exported XML looks like this:

<TaskerData sr="" dvi="1" tv="6.7.6-beta">
    <Task sr="task395">
        <cdate>1787164951612</cdate>
        <edate>1787164962284</edate>
        <id>395</id>
        <nme>Task Example</nme>
        <Action sr="act0" ve="7">
            <code>548</code>
            <Str sr="arg0" ve="3">Text</Str>
            <Int sr="arg1" val="0"/>
            <Str sr="arg10" ve="3"/>
            <Int sr="arg11" val="1"/>
            <Int sr="arg12" val="0"/>
            <Str sr="arg13" ve="3"/>
            <Int sr="arg14" val="0"/>
            <Str sr="arg15" ve="3"/>
            <Int sr="arg2" val="0"/>
            <Str sr="arg3" ve="3"/>
            <Str sr="arg4" ve="3"/>
            <Str sr="arg5" ve="3"/>
            <Str sr="arg6" ve="3"/>
            <Str sr="arg7" ve="3"/>
            <Str sr="arg8" ve="3"/>
            <Int sr="arg9" val="1"/>
        </Action>
    </Task>
</TaskerData>

Now we need to tell the Java Code where we want to insert our own values.

To do that, we use placeholders inside curly brackets {}.

Here is the same XML after replacing the values we want to customize:

<TaskerData sr="" dvi="1" tv="{TASKER_VERSION}">
    <Task sr="task279">
        <cdate>{CURRENT_TIME}</cdate>
        <edate>{CURRENT_TIME}</edate>
        <id>279</id>
        <nme>{TASK_NAME}</nme>
        <pri>100</pri>
        <Action sr="act0" ve="7">
            <code>548</code>
            <Str sr="arg0" ve="3">{FLASH_TEXT}</Str>
            <Int sr="arg1" val="0"/>
            <Str sr="arg10" ve="3"/>
            <Int sr="arg11" val="1"/>
            <Str sr="arg13" ve="3"/>
            <Int sr="arg14" val="0"/>
            <Str sr="arg15" ve="3"/>
            <Int sr="arg2" val="0"/>
            <Str sr="arg3" ve="3"/>
            <Str sr="arg4" ve="3"/>
            <Str sr="arg5" ve="3"/>
            <Str sr="arg6" ve="3"/>
            <Str sr="arg7" ve="3"/>
            <Str sr="arg8" ve="3"/>
            <Int sr="arg9" val="1"/>
        </Action>
    </Task>
</TaskerData>

Now copy this whole xml code and put it inside a set variable action and give this variable the name %xmltask. If you want to change to a different name you need to search for this line:

    String xml =
        tasker.getVariable("xmltask");

You can change xmltask to whatever name you want.

Tasker Version and Date

When you create or edit a Task, Tasker stores information such as the Tasker version and the creation/edit timestamps in the XML.

This isn't strictly required for our purpose, but the Java Code can automatically insert the current values.

Change:

dvi="1" tv="6.7.6-beta">

to:

dvi="1" tv="{TASKER_VERSION}">

And change:

<cdate>1787164951612</cdate>
<edate>1787164962284</edate>

to:

<cdate>{CURRENT_TIME}</cdate>
<edate>{CURRENT_TIME}</edate>

The Java Code will replace these placeholders with the installed Tasker version and the current timestamp.

Creating variables for the Task

Now we can use the same concept for the Task name and the text inside our Flash action.

Change:

<nme>Task Example</nme>

to:

<nme>{TASK_NAME}</nme>

And change:

<Str sr="arg0" ve="3">Text</Str>

to:

<Str sr="arg0" ve="3">{FLASH_TEXT}</Str>

Now we need to create the corresponding Tasker variables.

For example:

A1: Variable Set [
     Name: %task_name
     To: Task Creation Test
     Structure Output (JSON, etc): On ]
A2: Variable Set [
     Name: %flash_text
     To: Hello World
     Structure Output (JSON, etc): On ]

So we now have:

%task_name = Task Creation Test
%flash_text = Hello World

The first variable will become the Task name, and the second will become the text inside the Flash action.

Connecting the Tasker Variables to the XML

Now open the Java Code action and scroll down until you find:

    // --------------------------------------------------
    // 5. Replace Tasker variables
    //
    // Format:
    //
    // replaceVariable(
    //     xml,
    //     "XML_PLACEHOLDER",
    //     placeholderRequired,
    //     "tasker_variable",
    //     variableRequired
    // );
    //
    // --------------------------------------------------

This is where we tell the Java Code which Tasker variables should be inserted into the XML.

The template is:

    xml =
        replaceVariable(
            xml,
            "XML_PLACEHOLDER",
            false,
            "tasker_variable",
            false
        );

For example, to connect our Task name:

    xml =
        replaceVariable(
            xml,
            "TASK_NAME",
            true,
            "task_name",
            true
        );

The values mean:

"TASK_NAME" is the XML placeholder.

true = the XML "TASK_NAME" placeholder must exist; otherwise, an error is returned.

"task_name" is the Tasker variable name.

true = the Tasker variable must contain a value; otherwise, an error is returned

Notice that we don't include % when specifying the Tasker variable name.

For our Flash text, we can add:

    xml =
        replaceVariable(
            xml,
            "FLASH_TEXT",
            true,
            "flash_text",
            true
        );

You can add as many variables as you need using the same format.

Required vs. optional placeholders and Tasker variables

  • The first Boolean controls whether the XML placeholder is required:
    • true means the XML placeholder must exist. If it is missing, the Java Code stops and displays an error.
    • false means the XML placeholder is optional. If it doesn't exist, it is simply ignored.
  • The second Boolean controls whether the Tasker variable is required:
    • true means the Tasker variable must contain a value. If it is missing or empty, the Java Code stops and displays an error.
    • false means the Tasker variable is optional. If it is missing or empty, it is replaced with an empty value.

So the format is:

replaceVariable(
    xml,
    "XML_PLACEHOLDER",
    true,           // XML placeholder required
    "tasker_variable",
    false            // Tasker variable doesn't required
);

This Java code can also auto create a Project but i am pretty sure users wouldn't need to use it. If you really want to you just need to search inside your xml project code the name of your project like here:

<name>New Project</name>

And change it to something like this:

<name>{PROJECT_NAME}</name>

Then you need to just edit your java code to match your placeholder and Tasker variable

    xml =
        replaceVariable(
            xml,
            "PROJECT_NAME",
            true,
            "project_name",
            true
        );

The result

Now, when we run the Java Code together with our Variable Set actions, it will:

  1. Take our XML template.
  2. Replace the placeholders with our Tasker variables.
  3. Insert the current Tasker version and timestamp.
  4. Validate the resulting XML.
  5. Compress the XML using GZIP directly in memory.
  6. Convert it to Base64.
  7. Create the taskertask:// Data URI.
  8. Open it.
  9. Tasker asks whether we want to import the new Task.

Here's a demo of how it looks:

Demo video

Using this in a real project

I took this idea and incorporated it into another project of mine that allows users to run commands in Termux without using a Tasker plugin.

I created a scene that helps the user build the required configuration, and with just a few clicks it can generate a new Task containing all the actions and code they need.

Here's a demo of that:

Demo video inside a project

Hopefully this will be helpful to someone with his projects

reddit.com
u/Nirmitlamed — 2 days ago
▲ 1 r/tasker

How would you achieve that in Scene V2 (dynamically change Enabled element option)?

Never mind, i have found my mistake and why it didn't work for me (forgot to add % to a variable and typed the wrong word).

The solution is to use the main Screen inside the tree and then choose "Event Handling" and then Variable Changed and do all setup there.

-----

Lets say i have a Button, and i want this button to be off (using the Enabled option) until i write something inside a Text Input.

How can i achieve that?

reddit.com
u/Nirmitlamed — 3 days ago
▲ 0 r/tasker

Does someone knows how to create a Tasker deep link?

I have found the solution, i think it deserve different post to share with you my findings. I will try to post as soon as possible.

Basically i want:

  1. Using xml data of a task
  2. Convert this xml to Tasker deep link uri that starts like this: taskertask://

The basic idea is to create a dialog that will ask a user to insert some data (like the name of the task and some parameter of some actions inside it) and that data will create the whole xml file/text task and then it will convert it to taskertask:// uri url. Then i can open this url automatically to ask the user if he wants to import the task he just created.

Any tips will be welcomed.

Sorry in advance if i don't reply immediately.

reddit.com
u/Nirmitlamed — 4 days ago
▲ 3 r/tasker

What is the best approach for child phone control (app freezing & internet access)?

Hi everyone,

I’m trying to figure out the best, most reliable way to control app and internet access on a child's phone (with blocking/restricting apps being the higher priority).

Here are the methods I’ve researched so far and the challenges I’m running into:

1. Shizuku

  • Pros: Highly capable and probably the cleanest way to control app-level and internet access via eBPF without needing a local VPN.
  • Dealbreaker: If the phone reboots and isn't connected to a trusted Wi-Fi network, Shizuku loses its privilege token. All rules reset, and apps regain internet access until accessing to a trusted Wi-FI network.

2. Tasker with Device Owner / Device Admin (App Freezing/Suspension)

  • Pros: Tasker as Device Owner provides powerful, native actions to suspend/freeze apps directly. It doesn't rely on third-party services and persists across reboots.
  • The Challenge: I haven't found a way to pull or generate a dynamic list of currently frozen or suspended apps. To keep track, I currently have to maintain a manual list of package names. I can work around this, but it’s not ideal.

3. Internet Restriction

  • Local VPN setups (like Tasker's native Network Access action or NetGuard) work well without root, but they can degrade network performance/battery life and block the phone from using a real VPN service if needed. Using Shizuku is probably the best way.

Questions:

  1. Is there a way to get a list of all currently frozen/suspended apps on Android when using Device Owner?
  2. Does anyone have alternative suggestions or workflows for managing app limits and internet access reliably without full root access?

Thanks for any insights!

reddit.com
u/Nirmitlamed — 6 days ago
▲ 9 r/tasker

Sharing a project that executes Termux commands without using the Termux:Tasker plugin

Right off the bat, I want to say that I am not a developer and I don't know Java. I spent a couple of hours using AI to make this as stable as possible, and hopefully users with coding knowledge can help refine and improve this further for the community because I think this concept is pretty neat (or not?).

Termux:Tasker is an awesome plugin and one of my favorite tools, so huge respect to the dev who built it for us.

That said, I sometimes prefer having direct control over my setup without being solely dependent on external plugins. After discovering that I could recreate some of Termux:Tasker's functionality using Tasker's Java Code action (thanks to AI), and hearing that Termux:Tasker has issues running on newer Android version (Android 17), I decided to build a standalone alternative (alternative is a big word but you get the point) using Java Code actions and Termux intents directly.

Links & Code

https://reddit.com/link/1vnguqv/video/yof75i1lbyjh1/player

Special thanks to aasswwddd for the suggestion to build a scripted object and store it as a global Java variable. This allows calling the script object cleanly from anywhere in Tasker and passing in custom parameters.

Setup Note

Since the script object is stored in a Java variable, it clears whenever Tasker restarts or the device reboots. The workaround is to include a profile triggered by Event -> Tasker -> Monitor Start to automatically re-initialize it.

How to Use

Here is a basic example of how the execution code looks in practice:

Run a command:

int TIMEOUT_SECONDS = 10;
String TERMUX_BACKGROUND = "true";
String TERMUX_WORKING_DIRECTORY = "";

termux_Plugin.call();

run(
    "bash",
    "-c",
    "echo Hello World"
);

Options & Arguments:

  • Timeout: Set TIMEOUT_SECONDS to your desired duration in seconds, or set it to 0 for unlimited execution time.
  • Background Mode: Toggle TERMUX_BACKGROUND to "true" or "false" depending on whether you want Termux running in the background or foreground.
  • Termux Working Directory: Empty value String TERMUX_WORKING_DIRECTORY = "" Termux's default working directory. Or add a path to set a different directory: String TERMUX_WORKING_DIRECTORY = "/storage/emulated/0/Download"
  • Optional: You actually don't have to add TIMEOUT_SECONDS, TERMUX_BACKGROUND and TERMUX_WORKING_DIRECTORY to your code, i am giving an example down below in the post.
  • Command Arguments: The run() and runScript() methods takes 3 arguments:
    1. The interpreter ("bash", "python", etc.)
    2. The flag ("-c" for inline commands)
    3. The command itself ("echo Hello World")

Run A Script File

If you want to run a script file instead of an inline command, pass the file path (i have added a space between '.sh' because of reddit violations guide) as the second argument and null as the third:

int TIMEOUT_SECONDS = 10;
String TERMUX_BACKGROUND = "true";
String TERMUX_WORKING_DIRECTORY = "";

termux_Plugin.call();

run(
    "bash",
    "/storage/emulated/0/Download/my_script.s h",
    null
);

If you set a working directory you don't need to give the full path of the file and just put the name of the file like this:

int TIMEOUT_SECONDS = 10;
String TERMUX_BACKGROUND = "true";
String TERMUX_WORKING_DIRECTORY = "/storage/emulated/0/Download";

termux_Plugin.call();

run(
    "bash",
    "my_script.s h",
    null
);

If you have a filename with a space it will accept that too, you just need to add single quotes between:

int TIMEOUT_SECONDS = 10;
String TERMUX_BACKGROUND = "true";
String TERMUX_WORKING_DIRECTORY = "/storage/emulated/0/Download";

termux_Plugin.call();

run(
    "bash",
    "'my script.s h'",
    null
);

Run a Multi-Line Script Using a Tasker Variable

I have now added the ability to run multi-line script code stored in a Tasker variable. You can write the code exactly as you would write it inside a script file.

For example, you can create a Tasker variable called %my_script containing:

NAME=Tasker
echo Hello $NAME
echo Current directory:
pwd

The Java Code will then look like this:

int TIMEOUT_SECONDS = 10;
String TERMUX_BACKGROUND = "true";
String TERMUX_WORKING_DIRECTORY = "";

termux_Plugin.call();
runScript(
    "bash",
    "my_script"
);

Note: my_script is the Tasker variable name, without the % symbol.

You can also use a different interpreter instead of Bash. For example, for Python:

runScript(
    "python",
    "my_script"
);

This allows you to write multi-line Bash, Python, or other supported script code directly in a Tasker variable without having to create a separate script file.

You also don't have to add TIMEOUT_SECONDS, TERMUX_BACKGROUND and TERMUX_WORKING_DIRECTORY. If don't set them at all they return to their default:

Default:
int TIMEOUT_SECONDS = 30;
String TERMUX_BACKGROUND = "true";
String TERMUX_WORKING_DIRECTORY = "/data/data/com.termux/files/home";

So you can just run your code like this if you are fine with their defaults values:

termux_Plugin.call();

run(
    "bash",
    "-c",
    "echo Hello World"
);

Or like this with a script file:

termux_Plugin.call();

run(
    "bash",
    "'my script.s h'",
    null
);

Or like this with a multi-line script Tasker variable:

termux_Plugin.call();

runScript(
    "bash",
    "my_script"
);

Output Variables

This script populates standard Tasker variables so you can easily inspect and react to the output:

  • %tm_stdout
  • %tm_stderr
  • %tm_exitcode
  • %tm_success
  • %tm_timeout
  • %tm_error

And they also uses UTF-8 to support more than just English.

Just to clarify, it will wait until Termux finishes executing the command before proceeding to the next action, which wasn't possible using Tasker Function for example.

Error Handling

I have tried to make the plugin as robust as possible. In earlier versions, an error could leave a temporary folder behind in the Tasker folder. After extensive testing and several improvements, temporary folders are now automatically cleaned up, including when errors occur.

I have tested various scenarios, including successful commands, command failures, timeouts, script failures, and unexpected errors. Based on these tests, the cleanup and error-handling system appears to be very robust.

Final Word

Hopefully, someone finds this helpful and can help improve it further! To be clear, this isn't meant to be a full replacement for the official Termux:Tasker plugin, but rather an alternative light-weight approach.

reddit.com
u/Nirmitlamed — 8 days ago
▲ 6 r/tasker

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?

reddit.com
u/Nirmitlamed — 13 days ago
▲ 2 r/tasker

How do you add Tasker icon/shortcut on Android TV home screen?

Solution:

Use this website to create apk very easily. I have done this using my computer and then push the apk file to my AT box but you can also do that inside the AT box if you have browser with mouse and keyboard or just use it's Android app:

https://atvlauncher.trekgonewild.de/index.php

=========================

So just recently i thought about using Tailscale on my Android TV box since it is always connected to a power supply and with Tasker i could enable and disable Tailscale remotely when i need. So i have sideloaded Tasker and thankfully i have managed to setup everything, However, to open Tasker i need to go to apps settings because it doesn't have a shortcut on the home screen.

What is the best solution you all have found to create a shortcut for Tasker on AT home screen?

reddit.com
u/Nirmitlamed — 20 days ago

Voice call doesn't work on macOS Tahoe

Hi all, So i was trying to make a voice call in Rustdesk but the other side can't hear me. I saw that Rustdesk lacks microphone permission but the problem is that the app isn't even on the permissions list and i can't add it manually.

I also tried with this command to make a request for permission:

/Applications/RustDesk.app/Contents/MacOS/RustDesk

However it will request only for display which is already turned on.

I also try to reset permission but it didn't work:

tccutil reset Microphone com.carriez.RustDesk 

What els can be done to make it work?

reddit.com
u/Nirmitlamed — 3 months ago
▲ 2 r/mac

I need help to find a better solution to fully awake a Mac remotely

Hi all,

I have an old Intel MacBook Pro that I’m using as a remote download/media server for my TV box. Most of the time the Mac is sleeping, so I needed a way to wake it remotely whenever I want to send torrents or access files.

I found that the following script works very reliably:

python3 -c 'import socket; m="00:0e:c6:49:22:01"; b=bytes.fromhex(m.replace(":","")); p=b"\xff"*6+b*16; s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM); s.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1); s.sendto(p,("192.168.1.255",9)); print("sent")' && open vnc://192.168.1.5

What this does:

  1. Sends a Wake-on-LAN packet
  2. Opens Screen Sharing (VNC)

This wakes the Mac completely, almost like a real user is using it. After that, the Mac behaves normally and stays awake according to the regular macOS sleep timer.

The problem is that I want a cleaner background solution:

  • no Screen Sharing window opening
  • no manual interaction
  • no need to close the VNC window afterward

I tried using SSH with caffeinate, for example:

  • caffeinate -u
  • caffeinate -dimsu
  • timed versions with -t

But this doesn’t behave the same way as Screen Sharing. It either:

  • only temporarily prevents sleep,
  • keeps the Mac awake indefinitely,
  • or requires manually stopping caffeinate.

What I’m looking for is:

  • a way to remotely “fully wake” the Mac similar to Screen Sharing/VNC,
  • but entirely in the background,
  • while still allowing macOS to manage sleep normally afterward.

Does anyone know a better approach for this on macOS?

Thanks!

reddit.com
u/Nirmitlamed — 3 months ago
▲ 1 r/tasker

I hope Joao can see this post because i am having a problem with setting Join extension on my new computer.

I wanted to migrate everything from my old computer to my new one. I am using Brave browser and I used its sync capabilities to transfer data and extensions. I think this made things worse. Join on the new computer didn’t have a name as a device so i can't interact with it using my phone. I tried to disable Join on the old computer and then reinstalling it on the new one but i get the same problem.

I did a diagnose and got this error:

"Testing registration on Join's server... Error: Invalid registerDevice response: Must provide regId"

Do you have any suggestions?

u/joaomgcd

reddit.com
u/Nirmitlamed — 4 months ago