Javascriptlet Help

760 views
Skip to first unread message

Easier

unread,
May 11, 2013, 6:23:19 PM5/11/13
to tas...@googlegroups.com

Hi all~


I have been learning Javascriptlet through user guide recently but hard to understand some points.
Please kindly answer if available, very basic level.

Q1.  Most of actions in UserGuide start with string of "var = ok" but some actions has no that string.  
What is the difference and should I start an action with the string as said in the usgerguide ??  I tried both but no difference....

Q2. We use "If condition" frequently like "do something if it is true" or something but no explanation how to add this If condition in the series of javascript actions.
I mean not single javascriplet action but in multiple actions for example as follows.

This is just for example...

A1. Variable set %Sample, "hard"
A2. showScene();elemText() If %Sample is set;eleVisibility();
A3. destroyScene();

Should I use two lines like A1 showScene();elemText()eleVisibility() If %Sample is set A2 showScene();elemVisibility();  if %Sample isn' set 
I think there might be a pattern of "if else end if" but i can not even guess... Any advice how to add ?? 


Thanks

Matt R

unread,
May 11, 2013, 10:21:04 PM5/11/13
to tas...@googlegroups.com
I would search for a JavaScript tutorial online. The Tasker user guide isn't going to be sufficient to teach you everything about JavaScript if you are unfamiliar with it.

Matt

TaskerAholic

unread,
May 12, 2013, 3:55:36 AM5/12/13
to tas...@googlegroups.com
Thank you for your kind reply

It is kind of very big wall for beginner to access to Tasker Javascriptlet because, probably, the way of normal javascript and the type used in the Tasker might be slightly different.   

So, no way  but I have to get some tip from this group.


Thanks

2013년 5월 12일 일요일 오전 11시 21분 4초 UTC+9, Matt R 님의 말:

Bob Hansen

unread,
May 12, 2013, 1:23:34 PM5/12/13
to tas...@googlegroups.com
You can only run javascript using either the JavaScript Action or JavaScriptlet Action.
The difference between the two is that the JavaScript Action runs the java code that is in a source code file.
The JavaScriptlet Action runs code that is entered into the Action its self (good when only a few line are needed).
Any data between tasker and the java execution engine is passed through variables. In Tasker variables always start with %, like %myvar. To the java engine it will simply be myvar. 

Here is an example of using Tasker's JavaScriptlet action. *This example was created by Rich D
This is a simple search and replace done using javascript. Notice how the variables are set by Tasker and then the javascript references them with the same name without the %. 

Searchreplace (134)
A1: Variable Set [ Name:%replacewiththis To:RED Do Maths:Off Append:Off ] 
A2: Variable Set [ Name:%searchreplace To:BLUE Do Maths:Off Append:Off ] 
A3: Variable Set [ Name:%fileslista To:I want to replace BLUE Do Maths:Off Append:Off ] 
A4: JavaScriptlet [ Code:var searchrep = new RegExp(searchreplace,"g"); var fileslistc=fileslista.replace(searchrep,replacewiththis) Libraries: Auto Exit:On Timeout (Seconds):45 ] 
A5: Flash [ Text:%fileslistc Long:Off ]

The flash should be "I want to replace RED"

I expected it to be much more complicated, but it's not!

It will be much easier to help you if you can share the Tasker profile description by positing it. To export a description, long press on the profile to select it; tap the menu icon; from the popup menu select Export; select Description To clipboard. Paste the clipboard contents into a post.

Hope you find this helpful...

TomL

unread,
May 12, 2013, 3:47:20 PM5/12/13
to tas...@googlegroups.com
Not to be too pedantic, but there is a critical difference between javascript code and java code.

Javascript is an interpreted language supported by browsers and Tasker. Usually one means javascript if speaking of scripts or JS code.

Java code is a compiled language, with nothing in common with javascript. Other terms commonly associated with java code is JAR files and Java Virtual Machines.

Tom

TaskerAholic

unread,
May 12, 2013, 10:46:42 PM5/12/13
to tas...@googlegroups.com

Thank you for sharing indeed.

Your tips will be Big help to understand how to approach.


Have a nice day~

TaskerAholic

unread,
May 13, 2013, 8:58:45 PM5/13/13
to tas...@googlegroups.com
Dear Bob,


Thank you for your kind kind advice.
It works well. : - )

It seems the multiple javascriptlet actions is faster than normal Tasker action so I would like to change my tasks to JS type.
I think It is not difficult if I change them according to User guide but just one thing I can not figure is "If condition", not in the single action but in the middle 
of JS actions like  ~;~;if var is set, do something endif;~;~; 

Checking the user guide, I found "if condition" using "VAR=="Value" format but one thing I could not figure out is how to make the condition if any variable is set or not..  The reason I want to know this is because I have to get the variable value from Variable query action(I do not know the value).  If can not use "=="...

Do you by any chance know how to make the condition instead of "==" ??   


BR


2013년 5월 13일 월요일 오전 2시 23분 34초 UTC+9, Bob Hansen 님의 말:

Bob Hansen

unread,
May 13, 2013, 9:35:05 PM5/13/13
to tas...@googlegroups.com
You would use a series of IF statements - one for each variable 

If varA Is Set
   If varB Is Set
      If varC Is Set
         *
            *
               If var G Is Set
               < do this >

The above statement requires all variables be set before < do this > will happen.
Note: Be sure to Clear all the variables at the start of the Task.
Reply all
Reply to author
Forward
0 new messages