Variable editor tool

Variable editor tool

This is a tool script to help editing the list of lightning variables.

It lets you modify current variables and/or create new ones.

How to use it:

Launch the script, the list of all current variables and an extra ‘create a variable’ entry will be shown.

Click a variable to see it’s type and value. You can modify it’s value and save it. If you click cancel it will ask to delete it.

If you choose ‘create a variable’ input a name and a value and it will be created.

Note: the variables are set using lightning’s action ‘set a variable’. This means that the value is converted to it’s type by lightning itself, this script doesn’t use the script API calls because they need to specify a type.

For the ‘how does this work?’:

Saves lightning to force it to save the variables into the variables file.

Reads the available variables from the variables file (because there is no way to obtain the variables elsewhere, or at least I don’t know how)

Shows the list of variables to choose, a lot of prompts, etc.

To set/create a value it calls lightning activity ‘set a variable’.

To delete a variable it calls LL.getVariables().edit().setString(name,null).commit();

]]>

20 Commentsto Variable editor tool

  1. Anonymous says:

    < ![CDATA[

    //classes


    LL.bindClass(“android.app.AlertDialog”);


    LL.bindClass(“android.content.DialogInterface”);


    LL.bindClass(“java.io.BufferedReader”);


    LL.bindClass(“java.io.FileReader”);


    LL.bindClass(“java.io.File”);



    //global variables


    var newvariabletext=” — create a new variable — “;


    var vars;


    var names;



    //starts


    show();






    function show(){


    LL.save();//save to force the file to be updated


    vars=JSON.parse(read(“data/data/net.pierrox.lightning_launcher_extreme/files/variables”));//reads the content of the file


    names=vars.v==null?[]:vars.v.map(function(a){return a.n+”: ‘”+a.v+”‘”});//extracts the variable names, if any


    names.push(newvariabletext);//adds the ‘create variable’ entry



    list(names,clicked,”Choose a variable, or create a new one”);//shows the list



    }





    //when clicked an element


    function clicked(dialog,which){



    var variable=vars.v[which];


    if(which==names.length-1){


    //the ‘add a variable’ entry chosen


    addvariable();


    }else{


    //a variable chosen


    editvariable(variable);


    }


    setTimeout(show,0);//shows the list again. On a timeout so the startActivity() is correctly launched before


    }





    //editing a variable


    function editvariable(variable){



    var name=variable.n;



    //gets it’s type


    var llvar=LL.getVariables();


    var type=llvar.getType(variable.n);



    //gets its value


    var oldv=variable.v//vars.v.filter(function(obj){return obj.n==name})[0].v;



    //asks for a new value


    var newv=prompt(name+” (“+type+”)”,oldv);


    if(newv==null){


    //cancelled. delete?


    if(confirm(“Do you want to delete this variable?”))llvar.edit().setString(name,null).commit();


    return;


    }



    //update the value


    lightningcall(name,newv);



    }





    //adding a variable


    function addvariable(){



    var name=””;



    do{


    //ask for a not-used name


    name=prompt(“Name of the variable”,name);


    }while(names.indexOf(name)!=-1&& !confirm(“This variable name is already used, do you want to continue? (will be overwritten)”));



    if(name==null)return;//cancelled



    //asks for the value


    var value=prompt(“Value of the variable ‘”+name+”‘”,””);


    if(value==null)return;//cancelled



    //create the variable


    lightningcall(name,value);



    }





    //calls lightning action ‘set a variable’


    function lightningcall(name,value){



    var intent=new Intent.getIntent(“#Intent;component=net.pierrox.lightning_launcher_extreme/net.pierrox.lightning_launcher.activities.Dashboard;i.a=41;end”);//the base intent


    intent.putExtra(“d”,name+”/”+value);//the extra data



    LL.startActivity(intent);


    }









    //function to display a List in a Popup, where the user can select one item. Taken from Lukas Morawietz’s Multi tool script


    function list(items,onClickFunction,title){


    var builder=new AlertDialog.Builder(LL.getContext());


    var listener=new DialogInterface.OnClickListener()


    {


    onClick:function(dialog,which)


    {


    dialog.dismiss();


    setTimeout(function(){onClickFunction(dialog,which);},0);


    return true;


    }


    }


    builder.setItems(items,listener);


    builder.setCancelable(true);


    builder.setTitle(title);


    builder.setNegativeButton(“Cancel”,new DialogInterface.OnClickListener(){onClick:function(dialog,id){dialog.cancel();}});//it has a Cancel Button


    builder.show();


    }




    function read(filePath){


    var file=new File(filePath);


    var r=new BufferedReader(new FileReader(file));


    var s=””;


    var l;


    while((l=r.readLine())!=null)s+=(l+”\n”);


    return s.substring(0, s.length – 1);


    }

    ]]>

  2. Anonymous says:

    < ![CDATA[

    This is cool TrianguloY​ it will be helpful for most of the users.

    ]]>

  3. Anonymous says:

    < ![CDATA[

    Abdullah Alahdal​ thanks 🙂


    Note: I updated the script with a little improvement, if you already copied it, copy it again.

    ]]>

  4. Anonymous says:

    < ![CDATA[

    great



    thanks I’ll test it

    ]]>

  5. Anonymous says:

    < ![CDATA[

    Working perfectly.You’re a boss

    ]]>

  6. Anonymous says:

    < ![CDATA[

    TrianguloY could you add the value of the variable on the list


    And possible to have white letters on black background ?

    ]]>

  7. Anonymous says:

    < ![CDATA[

    The first, yes.


    The second, no (you will need to specify a custom theme)

    ]]>

  8. Anonymous says:

    < ![CDATA[

    TrianguloY OK


    And is it possible to launch the keyboard after chosing a variable ?


    Noticed the value is selected but we have to click ,delete the value and type new value


    Would be fantastic

    ]]>

  9. Anonymous says:

    < ![CDATA[

    Bruno-Isa LAMOUR-ARNOULD done (it was easy). Script updated.

    ]]>

  10. Anonymous says:

    < ![CDATA[

    That second suggestion is not possible.


    I’m using lightning built-in dialogs (for easier access)

    ]]>

  11. Anonymous says:

    < ![CDATA[

    TrianguloY​​


    OK seen the script updated.Thx

    ]]>

  12. Anonymous says:

    < ![CDATA[

    Bruno-Isa LAMOUR-ARNOULD if not, were? 😉 (the answer could be ‘in the wiki’, but I didn’t posted it yet)

    ]]>

  13. Anonymous says:

    < ![CDATA[

    TrianguloY please post on the wiki

    ]]>

  14. Anonymous says:

    < ![CDATA[

    Script doesn’t work anymore. Can someone check it and fix?


    Is there another way to delete variables created by mistake?

    ]]>

  15. Anonymous says:

    < ![CDATA[

    script working fine for me



    what is your issue ?

    ]]>

  16. Anonymous says:

    < ![CDATA[

    I can see the list of variables.


    When I tap on any of them the list is only reloading. But if I tap on any with content ‘notag’ then I get error.


    What could it be?


    BTW, when I tap “show the script” button in error window, then there is a message “unknown or deleted script…” and script doesn’t opening.


    https://plus.google.com/photos/

    ]]>

  17. Anonymous says:

    < ![CDATA[

    That doesn’t seem an error from this script. I could be wrong, but I think that you are using that variable incorrectly on a binding, and so when you update it from the variable editor it reloads and shows the error. Check the bindings where you are using that, and check they are correct (notag is a string? If so you need to set it between ” )


    When you click open script it opens nothing because there is no script, that’s a binding.

    ]]>

  18. Anonymous says:

    < ![CDATA[

    And to delete a variable, select it, press cancel, and then it will prompt to delete (press ok)

    ]]>

  19. Anonymous says:

    < ![CDATA[

    when I tap on a variable I can see the content and able to change it

    ]]>

  20. Anonymous says:

    < ![CDATA[

    when I tap on a variable there was nothing except list reloading (and an error with “notag”)


    But after some modifications in bindings (I guess problem was in “) and rebooting I can see the content and can change it. And even delete it.Now my bindings are



    if (‘$calendar_event1_tag’==’today’) {


    return 255*(animate(‘$ll_second’)%3);


    }


    else return 255;



    and



    if (‘$calendar_event1_tag’==’past’) {


    return 0xffff0000;


    }


    else return 0xffffffff;



    But I steel get the similar error after editing (without changing) some variables.


    I have


    $calendar_event1_tag


    $calendar_event1_time


    $calendar_event1_title



    $calendar_event5_tag


    $calendar_event5_time


    $calendar_event5_title


    From 1 to 3 are displayed and tag is using in bindings. But 4 and 5 are not used at all.


    All titles are OK


    All tags are causing an error


    Times from 1 to 3 are causing an error, but 4 and 5 are OK.



    It’s strange. But it’s not a script problem.


    Script is working great now. Thanks TrianguloY and Bruno-Isa LAMOUR-ARNOULD

    ]]>

Leave a Reply

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