Calling your scripts from Tasker

2,300 views
Skip to first unread message

Dave Smart

unread,
Mar 22, 2015, 6:51:39 AM3/22/15
to androi...@googlegroups.com
Hi Guys,

Using the new Android Intents support, you can now call your scripts from the popular tool 'Tasker'.  This enables you to schedule scripts at certain times or trigger scripts when certain events occur or you arrive in certain places.

Here is a demo program which you should build into an APK called "TaskerTest" and then install it.


//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );

//Create a text box.
txt = app.CreateText( "", 0.95, 0.6 , "left,multiline" );
txt.SetBackColor( "#ff222222" );
txt.SetTextSize( 22 );
lay.AddChild( txt );
//Add layout to app.
app.AddLayout( lay );
}

//Handle data sent from other apps.
function OnData( isStartUp )
{
    //Display intent data.
var intent = app.GetIntent();
if( intent )
{
   if( intent.extras )
            txt.SetText( "Battery Level = " + intent.extras.bat + "%" ); 
}
}


The information you should enter into your Tasker intent is as follows:-

Cat -> Default
Extra -> bat:%BATT
Package -> com.myname.taskertest
Class -> com.smartphoneremote.androidscriptfree.AndroidScriptFree
Target -> Activity

The rest of the field can be left blank.  
(Note: Your package name might be slightly different if you have previously built APK's)

If you want to stuff more information into the 'Extra' field you can use JSON something like this-: 

Extra ->  json:{ "msg":"Hello", "count": 42 }

and then parse it at the other end using the JSON.parse method.



 

Bill DeWitt

unread,
Sep 26, 2015, 9:08:05 PM9/26/15
to AndroidScript
I was looking for this because I had got about halfway done making Tasker write a file and getting DroidScript to read it when it opened with the simple App open of Tasker. I have about a hundred items, should I just put them in extra > JSON instead?

Eric Geer

unread,
Sep 12, 2016, 3:55:19 PM9/12/16
to DroidScript
I tried everything to get this to work. Copied it verbatim,minus the Tasker variable, which I switched for my own, and tested the variable for value before. Double-tripple checked spelling, etc. Text continually displays as undefined. I'm wondering if there are app permissions required? How do I debug this?

Eric Geer

unread,
Sep 13, 2016, 12:21:40 AM9/13/16
to DroidScript
Bump.  Really need to get this to work.  How can I debug it so I can see the data handoff?

Dave Smart

unread,
Sep 13, 2016, 2:21:15 AM9/13/16
to DroidScript
Hi Eric,

I think you need to send us some script examples and Tasker screen shots for us to fully understand the problem and test it ourselves.

Eric Geer

unread,
Sep 13, 2016, 9:26:54 PM9/13/16
to DroidScript
You got it! https://youtu.be/CXAF5ypDIQw

Thanks for watching!

Steve Garman

unread,
Sep 14, 2016, 2:18:12 AM9/14/16
to DroidScript
Eric,
You are sending that intent to a package called
com.myname.taskertest
so you will need to build and install an apk with that packageName.

Eric Geer

unread,
Sep 14, 2016, 3:08:53 AM9/14/16
to DroidScript
I see, that wasn't clear to me by the sample. Is there a way Droidscript can receive it without building the APK? Only reason I've been holding off from purchasing the APK builder plugin was I just wanted to make sure it will fully replace my current Tasker implementation, but I still don't have an AutoRemote replacement yet. I'm also not planning to sell the app on the store, but that could change. I've placed a request in AutoApps to build a Droidscript plugin, but who knows if/when that would happen. I really like the cloud push technology they use as it's super responsive, minimal data usage, and doesn't require firewall NAT.

Another great plugin possibility would be IFTTT. A receiver/sender plugin to IFTTT would open up some seriously crazy oportunities, I.e. controlling home appliances or responding to them. I could accomplish what I needed with a Do button or Maker channel.

Steve Garman

unread,
Sep 14, 2016, 3:13:38 AM9/14/16
to DroidScript
I am not in a position to test this right now but try using the packageName
com.smartphoneremote.androidscriptfree

Eric Geer

unread,
Sep 14, 2016, 1:41:58 PM9/14/16
to DroidScript
Thanks Steve, I did test it with that, with same results.  Should I just purchase the APK builder plugin?  Not sure it will serve my purpose or not.

Dave Smart

unread,
Sep 16, 2016, 8:52:04 AM9/16/16
to DroidScript
If you want to use Tasker intents in the DS IDE rather than an APK, then you need to use this class name:-

com.smartphoneremote.ioioscript.NewActivity

the package name remains the same (i.e. com.smartphoneremote.androidscriptfree )

You can then specify the script to run inside DS using taskers 'Extra' parameter with a full path to the script like this:-

app_file:/sdcard/droidscript/taskertest/taskertest.js

The "Receive Intent" DS sample is a good starting point for this experiment

Eric Geer

unread,
Oct 26, 2016, 9:38:27 PM10/26/16
to DroidScript
Tried this, but still no luck. Anyone get this to work?

Dave Smart

unread,
Oct 27, 2016, 6:06:19 AM10/27/16
to DroidScript
Hi Eric,

Can you send us a screen shot of your tasker setup page please.

Eric Geer

unread,
Oct 28, 2016, 6:41:10 PM10/28/16
to DroidScript
Ok, here is the code:

//This example shows how to receive data from other apps
//like 'Tasker' which allow sending of Android Intents.

//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );

//Create a text label and text boxt.
txt = app.CreateText( "Intent Data:" );
lay.AddChild( txt );
txt1 = app.CreateText( "", 0.95, 0.6 , "left,multiline" );
txt1.SetBackColor( "#ff222222" );
txt1.SetTextSize( 18 );
lay.AddChild( txt1 );

//Add layout to app.
app.AddLayout( lay );
}

//Handle data sent from other apps.
function OnData( isStartUp )
{
//Display intent data.
var intent = app.GetIntent();
if( intent )
{

//Extract main data.
var s = "action: " + intent.action + "\n";
s += "type: " + intent.type + "\n";
s += "data: " + intent.data + "\n\n";

//Extract extras.
s += "extras:\n";
for( var key in intent.extras )
s += key+": "+intent.extras[key] + "\n";

txt1.SetText( s );
}
}

And the Tasker details:

This is the looping script. It flashes %BLUE for Bluetooth status so you know the Tasker has a working variable. Then it sends intent and loops:
https://goo.gl/photos/bZbbjecs41PSZQ1r6

Here are the actual intent details from Tasker:
https://goo.gl/photos/1Pmu1HE7Tem6JDVo7
https://goo.gl/photos/Q1DsRkeFCy6cjGpq9
https://goo.gl/photos/TvJdLWLHnqW6EqHo7

Eric Geer

unread,
Oct 28, 2016, 7:03:49 PM10/28/16
to DroidScript
So, to add more debugging to the script, I modified the following:


//This example shows how to receive data from other apps
//like 'Tasker' which allow sending of Android Intents.

//Called when application is started.
function OnStart()
{
    //Create a layout with objects vertically centered.
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );   

    //Create a text label and text boxt.
    txt = app.CreateText( "Intent Data:" );
    lay.AddChild( txt );
    txt1 = app.CreateText( "", 0.95, 0.6 , "left,multiline" );
    txt1.SetBackColor( "#ff222222" );
    txt1.SetTextSize( 18 );
    lay.AddChild( txt1 );

   
    //Add layout to app.   
    app.AddLayout( lay );
}

//Handle data sent from other apps.
function OnData( isStartUp )
{
       //Display intent data.
    var intent = app.GetIntent();
    if( intent )
    {
        console.log( "Receiving Intent: " + intent );
        if ( intent.extras )
        {
            console.log( "Receiving Extras:" + intent.extras);

            //Extract main data.
            var s = "action: " + intent.action + "\n";
            s += "type: " + intent.type + "\n";
            s += "data: " + intent.data + "\n\n";
       
            //Extract extras.
            s += "extras:\n";
            for( var key in intent.extras.intent )
                s += key+": "+intent.extras.intent[key] + "\n";
       
            txt1.SetText( s );
        }
    }
}

Now, even though I'm setting the Tasker script to update every 5 seconds, it only displays this once, and debugging doesn't show it receiving anything else.  So what it now shows me in the debug console is:

Receiving Intent: [object Object]
Receiving Extras:[object Object]
Txt.SetText( action: type: data: extras: )

Netpower8

unread,
Oct 29, 2016, 1:15:11 PM10/29/16
to DroidScript
you can see the contents of [object Object]...

Here's a function (from my plugin) you might need to see the contents of [object Object]

// ******************************
// * showObjProp
// ******************************
// show obj properties. save to clipboard for later use
function showObjProp(obj) {
var ss=JSON.stringify(obj,null,1);
alert(ss);
app.ShowPopup('JSON object save to clipbaord for easy paste reference');
app.SetClipboardText(ss);
} // showObj(obj)

Eric Geer

unread,
Oct 29, 2016, 2:48:37 PM10/29/16
to DroidScript
Hi Netpower,

Thanks for the input, but I think there's a different issue. That [object Obfect] only pops up once the first time it's loaded. My Tasker script goes every five seconds. I don't believe that those values are being delivered from Tasker, otherwise the debug would show a continual value updated.

Message has been deleted
Message has been deleted

Eric Geer

unread,
Nov 1, 2016, 12:19:59 PM11/1/16
to DroidScript
Bump

Dave Smart

unread,
Nov 2, 2016, 12:12:32 PM11/2/16
to DroidScript
OK,

I just tried it on my phone... the problem is that you need to give a key:value pair for the intent extras (DS expects this).

So instead of putting just %BLUE in Tasker, you need to put something like bluetooth:%BLUE instead

Also try this for debugging:-

 if ( intent.extras )
        {
            alert( JSON.stringify(intent.extras) );

Eric Geer

unread,
Nov 2, 2016, 1:32:15 PM11/2/16
to DroidScript
Thanks Dave,

So, from Tasker, I'm using intent.%BLUE.  Do I need to make it something other than "intent." before %BLUE?  I used "intent." because I will likely make different values to pass later on, and not just bluetooth.  Maybe I should change it to "message.%VALUE"?  I can't help but think I've already tried the original bat.%BATT from the sample.

I'll try adding the extra debugging steps.

Dave Smart

unread,
Nov 2, 2016, 1:38:56 PM11/2/16
to DroidScript
It's colon not dot.  Use this:-

bluetooth:%BLUE

Eric Geer

unread,
Nov 2, 2016, 6:00:10 PM11/2/16
to DroidScript
Ok, tried this, but just not getting it. Here's the extra debug info you asked:

https://goo.gl/photos/5XoZCj1CypPm6Jq8A

With the extras, suppose I use message:%BLUE in Tasker, how should my code read in DroidScript to receive that?

Dave Smart

unread,
Nov 3, 2016, 7:58:20 AM11/3/16
to DroidScript
That's not what I get.  You better send another screen shot of your tasker settings.  I need to see the 'extras' bit

Eric Geer

unread,
Nov 3, 2016, 2:04:04 PM11/3/16
to DroidScript
Hi Dave, FWIW, I get that JSON response weather Tasker is sending intent or not.  So it appears it has nothing to do with Tasker.  I'll re-capture the Tasker extras here in a bit.

Eric Geer

unread,
Nov 3, 2016, 4:02:32 PM11/3/16
to DroidScript

Dave Smart

unread,
Nov 3, 2016, 7:29:34 PM11/3/16
to DroidScript
Looks ok to me. 

What happens if you  manually send the intent from Tasker (without the looping etc)?

Are you leaving DS running in the background or shutting it down?

Note: You will always see intent data when you start an app because that is how activities are started.

Eric Geer

unread,
Nov 3, 2016, 8:36:58 PM11/3/16
to DroidScript
So I'm basically running the Tasker script, then opening the DroidScript testintent script after. I've tried both, leaving it open in the background, and switching back.

Dave Smart

unread,
Nov 4, 2016, 6:23:36 AM11/4/16
to DroidScript
But surely the DS testintent script is being opened for you by Tasker, you should not have to open it yourself?

Eric Geer

unread,
Nov 4, 2016, 5:18:10 PM11/4/16
to DroidScript
For my purposes, the app  will need to remain open.  I only want it to be able to receive info from Tasker while open.

Anyway, I threw out this idea as it just wasn't working for me.  I decided to go the file write/read route.  Much simpler, though I have to call a function using setInterval instead of getting data on the fly.

Bill DeWitt

unread,
Sep 4, 2018, 7:48:31 PM9/4/18
to DroidScript
Wow. Look at me responding to this post about three years ago. I don't even remember it.  I was pretty wrapped up in graduating from college at the time.  I think I was actually dealing with the same music selection problem. 

I was looking for this because I had got about halfway done making Tasker write a file and getting DroidScript to read it when it opened with the simple App open of Tasker. I have about a hundred items, should I just put them in extra > JSON instead?
Reply all
Reply to author
Forward
0 new messages