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

}

]]>

16 Commentsto Scripting help: Is there a way to get the position of the desktop via a script that runs in the background (vs.

  1. Anonymous says:

    < ![CDATA[

    use something other than getCurrentDesktop

    ]]>

  2. Anonymous says:

    < ![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

    ]]>

  3. Anonymous says:

    < ![CDATA[

    getContainerById


    but first you must find the id of the desktop you want

    ]]>

  4. Anonymous says:

    < ![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)

    ]]>

  5. Anonymous says:

    < ![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.

    ]]>

  6. Anonymous says:

    < ![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?

    ]]>

  7. Anonymous says:

    < ![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.

    ]]>

  8. Anonymous says:

    < ![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.

    ]]>

  9. Anonymous says:

    < ![CDATA[

    Thanks! I went with the variable approach, works perfectly

    ]]>

  10. Anonymous says:

    < ![CDATA[

    Hi, can you post the complete solution? I’m trying to move panels up/down based on the desktop being scrolled horizontally…

    ]]>

  11. Anonymous says:

    < ![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

    ]]>

  12. Anonymous says:

    < ![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…

    ]]>

  13. Anonymous says:

    < ![CDATA[

    Wait, got it to work with this.



    https://youtu.be/qoCh0ieq7PQ

    ]]>

  14. Anonymous says:

    < ![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​

    ]]>

  15. Anonymous says:

    < ![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.

    ]]>

  16. Anonymous says:

    < ![CDATA[

    My bad, it was Zooper that was draining…

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *