Scripting help: Is there a way to get the position of the desktop via a script that runs in the background (vs.
Scripting help: Is there a way to get the position of the desktop via a script that runs in the background (vs. running in desktop)?
Tried using this script below, but it only works when script is run in desktop, and not when run in background:
var page = Math.round(LL.getCurrentDesktop().getPositionX()/LL.getCurrentDesktop().getWidth());
if (page == -1) {
//actions to run
}
]]>« Update Italian translation (saved 02 July 2015 17:33) (Previous Post)
(Next Post) I have set for testing grid lines. »
< ![CDATA[
use something other than getCurrentDesktop
]]>
< ![CDATA[
thanks, what would be a good alternative? I’m trying to have LL figure out if my desktop is scrolled to the left of the home screen
]]>
< ![CDATA[
getContainerById
but first you must find the id of the desktop you want
]]>
< ![CDATA[
I managed to get the desktop id, and getContainerById works when script is launched from LL menu, but not when script is run in background (from Tasker)
]]>
< ![CDATA[
Maybe (not tested) the problem is that when it is in background it is not scrolled…it’s nothing because it is not loaded.
Suggestion: in the paused event of the desktop run a script that takes the current position and stores it in a tag. Then just get it from the background script.
]]>
< ![CDATA[
Thanks! Will try this out … with a variable so I can also use it in a binding. Just curious, what’s the difference between variable and tag?
]]>
< ![CDATA[
Wern-Yuen Tan
A tag is a string stored in an item, a container or a script. If the item/container/script is removed the tag is lost. It was the only specific way to store permanent data until now. (You can also in labels)
A variable is a new thing that lightning uses in bindings. It is not removed unless you do so. And when it changes lightning updates the binding that uses it.
What to use? What you prefer and you know more.
]]>
< ![CDATA[
To extend on TrianguloY’s reply, it cannot work safely because when a script is run in the background, the android Views may not have be loaded yet. In other word, the user interface may not have been constructed and nothing has to be displayed, hence no size nor position. The data model can be loaded from the persistent storage, including properties and some fixed geometry, but data that depends on the screen size (such as cell width and height for instance) are not available.
That doesn’t mean this is always the case, but since it may or may not work depending on a variety of factors, best is to a assume that it doesn’t work at all.
]]>
< ![CDATA[
Thanks! I went with the variable approach, works perfectly
]]>
< ![CDATA[
Hi, can you post the complete solution? I’m trying to move panels up/down based on the desktop being scrolled horizontally…
]]>
< ![CDATA[
set the following script on “Destop position changed” event
var page = Math.round(LL.getCurrentDesktop().getPositionX()/LL.getCurrentDesktop().getWidth());
var editor = LL.getVariables().edit();
editor.setInteger(“page”,page);
editor.commit();
the LL variable “page” can then be used in a binding
]]>
< ![CDATA[
I set the Position Changed event to run this script, and then binded the top property to $page.
But nothing happens when I scroll the page…
]]>
< ![CDATA[
Wait, got it to work with this.
https://youtu.be/qoCh0ieq7PQ
]]>
< ![CDATA[
My battery drain seems to have increased a lot since I made this change…
Is there anyway to optimize scripts that run when desktop position changes?
TrianguloY
]]>
< ![CDATA[
Unfortunately no. However it shouldn’t drain it more than before, the difference should be unnoticeable (because I expect that the animation is smooth right? )
If you want you can post the whole script to take a look.
]]>
< ![CDATA[
My bad, it was Zooper that was draining…
]]>