Using Tasker variables in Javascriptlet

2,034 views
Skip to first unread message

sam1am

unread,
Feb 11, 2013, 8:53:00 PM2/11/13
to tas...@googlegroups.com
I'm trying to use global to get variables from tasker, but it's not working. Here's my task:

1. Variable Set
Name %foo to 1

2. Javascriptlet
Code
var bar = global('foo');
flash(bar);

When I run the task it says undefined. What am I doing wrong? 

sam1am

unread,
Feb 11, 2013, 8:55:52 PM2/11/13
to tas...@googlegroups.com
I changed the tasker variable to all caps and now it works. 

TomL

unread,
Feb 11, 2013, 9:28:22 PM2/11/13
to tas...@googlegroups.com
Bingo. Var names with any cap letters are global in scope, vars in all lower case are local in scope.

Tom

jenksy

unread,
Jul 6, 2015, 12:51:26 AM7/6/15
to tas...@googlegroups.com
What about Tasker variables with MiXeD CaSe?  

I have a scene that passes information using CamelCase vars, but I'm having trouble reading them in a Tasker JavaScriptlet...  

Odysseos

unread,
Jul 6, 2015, 2:13:12 AM7/6/15
to tas...@googlegroups.com
All variables  having at least one capital letter, wherever located, are global variables. So, %Myvar, %MyVar, %myvaR, %mYvAr etc. are all global variables. In a Javascript you must refer to them using global statement : global("MyVar").
So,
A1 Variable set [%Myvar To: Hello Do Maths:Off Append:Off]
A2 Javascriptlet [ Code:alert(global("Myvar")); Libraries:Auto Exit:On Timeout(Seconds):45]
will show an alert saying Hello.
Reply all
Reply to author
Forward
0 new messages