Scripting question for those much more experienced.
Posted by: pierrot | on September 21, 2014
Scripting question for those much more experienced. Would it be possible in some way to get an incoming notification’s text and display it with an LLX dynamic text widget? I’m thinking things like a text message, missed call information, calendar notification, etc. I was thinking with apps like Tasker, AutoShare, and AutoNotification it might be possible. I just honestly have no idea where to start.
]]>
< ![CDATA[
Use a normal shortcut to display the text (icon hidden) instead of a dynamic text, then, with the current beta, it is possible to execute a LLX script from Tasker, with some data. These data can contain variables that are replaced inside Tasker. In the LLX script you can read this data and change the shortcut label for instance.
]]>
< ![CDATA[
Displaying more “notification type” data directly in the launcher is something I would really like to allow.
]]>
< ![CDATA[
Could you please give more details on how to change a shortcut label with Tasker.
I managed to replicate the example in the Tasker documentation but I’m not sure which script to use to change a label and how to apply it to a certain shortcut.
]]>
< ![CDATA[
Pierre Hébert I personally think it would be cooler /better to allow us to put tasker variables in the dynamic text and in shortcuts. . is this possible by chance? and if not could I request this? it would be cool to press the shortcut and have the shortcut name change according to set variables.
]]>
< ![CDATA[
Christian Ramuschkat on the scripting side this is something like: LL.getCurrentDesktop().getItemByLabel(‘name of your item’).setLabel(your_value);
Curtis Sylvester Jr. no unfortunately, the only way is to make Tasker do something when the variable changes. Tasker does not allow direct reading of a variable and neither does it notify other apps when its value changes
]]>
< ![CDATA[
fair enough. . it seemed like a good idea for when tasker sets a variable that the launcher can read that variable and display it as the name of a shortcut or in a dynamic text but not if tasker wont allow it to work. I’m surprised tasker let you turn llx into a plugin though
]]>
< ![CDATA[
Actually this technical solution is simple but solves many problems. In the end it works a bit like a discussion: A says something to B, and B can also speak to A.
If I had to use an image, I would say that direct variable reading is something like reading someone’s thought 🙂
Exchanging “messages” avoid the need for the “read+notify” mechanism.
]]>
< ![CDATA[
wait that’s it…. . i found an idea on how to do it. . when a tasker profiles conditions are met instead of setting a tasker variable (which can’t be read by the launcher) how about setting launcher variables that act the same way but only in the launcher. . much like setting a zooper widget that gets read by zooper it’ll be a launcher variable that gets read by the launcher. . would that work?
]]>
< ![CDATA[
I tried the following but get an error (At line 1: missing ) after argument list):
LL.getCurrentDesktop().getItemById(04000a).setLabel(test);
]]>
< ![CDATA[
04000a is wrong you probably mean 0x04000a
]]>
< ![CDATA[
Sorry, I’m just trying to understand how scripting works with LLX.
I changed ID to 0x4000a and now I get
ReferenceError: “test” is not defined
]]>
< ![CDATA[
The scripting language is Javascript, this mean you need to follow the Javascript syntax.
04000a is not a valid number: it looks like an hexadecimal value, but hexadecimal values need to be preceded with 0x in Javascript.
I don’t know what test is: is it a variable that contains the value to put in the label, or is it the value itself ? If this is the value, then it need to be enclosed in quotes or double quotes, this way: setLabel(“test”);
If not, then test should be a variable., and if you get a “reference error”, then it means the script engine cannot find a variable named test.
]]>
< ![CDATA[
Thanks for your explanation!
What I’m trying to achieve is a shortcut which displays an icon and the description of weather conditions.
The values for icon path and weather description should be Tasker variables (%icon & %desc).
test was meant to be the value, so after adding quotation marks it works as intended.
I’m afraid, creating a dynamic shortcut is not as easy as I hoped and I have to learn some scripting basics first.
It’s just difficult to find a point to start with.
]]>
< ![CDATA[
That is indeed very true, but the community is here to help 😉
]]>
< ![CDATA[
Christian Ramuschkat I was asking about the dynamic shortcut and even mentioned a possible solution to that but it’s up to Pierre Hébert to implement it.
]]>
< ![CDATA[
The following script will set the label of a certain item to the data provided by the Tasker task:
LL.getCurrentDesktop().getItemById(0x04000a).setLabel(LL.getEvent().getData());
The issue I have is, that everytime the script is executed it will throw me to the homescreen.
Is there a way to change that behavior?
I also tried to change the icon with the following:
LL.getCurrentDesktop().getItemById(0x04000a).setCustomIcon(LL.getEvent().getData());
In the data field I put the path to the png file.
Can anyone tell me what I’m doing wrong, since the script errors on execution.
Curtis Sylvester Jr.
Yes, it would be much easier if there was a way to set launcher variables within Tasker tasks.
Maybe it will be possible some day.
]]>
< ![CDATA[
Sorry if this is a bit late, but anyway:
Christian Ramuschkat
getItemById is a function of a container, but also of LL itself, I guess launching just
LL.getItemById(0x…
won’t move the current desktop, try it.
]]>
< ![CDATA[
Oh, and also this should work (didn’t test myself!)
LL.getItemById(0x04000a).setCustomIcon(LL.createImage(LL.getEvent().getData()));
]]>
< ![CDATA[
Oh I forgot the LL.createImage.
Thank you, it works now.
Can you think of a way to avoid being thrown to the homescreen when the script is executed?
]]>
< ![CDATA[
Yes there is a way to do that, but it is not so trivial to implement. The reason is both easy and complex to understand.
What happens here is that in order to execute an action, no matter which (a script, a desktop change, and so on), the launcher need to be alive. But on Android, when an application is not in foreground, it may not be alive. For this reason, it is brought back to you when the action is triggered from Tasker or any other app. That’s the main reason.
Of course there are ways to keep something running in the background and LLX actually do that in some occasions. The difference is that in this situation not everything is loaded, and the context to execute an action is not always there.
]]>