Minimalistic page indicator

Minimalistic page indicator

Talking about indicators, I couldn’t stop thinking how to make a script. There is already one in the wiki, but I wanted one a bit more ‘stock’.

I started thinking complex ways of doing it, but then I realize that simplicity is the best in this case.

So I made one in 34 lines of code, easy to understand (this is an objective adjective, I know) and easy to set up.

Important: due to the custom characters I use, the maximum number of pages is 10. However you can change the character as you wish.

Instructions:

– Copy/paste this script as a new one

– Set it to run in the ‘position change’ event of the desktop

– place an item (recommend: shortcut to ‘do nothing’ and pinned) and label it ‘indicator’.

– [Recommended] Check the snap to pages and uncheck ‘fit desktop to items’ in scrolling options.

It automatically adapts to the desktop, for this reason the home page may not be the number 1.

————————————-

//The special characters

var fill = “➊❷❸❹❺❻❼❽❾❿”;

var empty = “①②③④⑤⑥⑦⑧⑨⑩”;

//Vars

var cont = LL.getEvent().getContainer();

var width=cont.getWidth();

var left = Math.round(cont.getBoundingBox().getLeft()/width);

var right = Math.round(cont.getBoundingBox().getRight()/width)-1;

var page = Math.round(cont.getPositionX()/width);

//With zoom –> no page selected

if(cont.getPositionScale()!=1) page=NaN;

var ind = “”;

var flag=false;

//if more pages, just show “…”

if(right-left+1>empty.length){

right=left+empty.length-1;

flag=true;

}

//indicator

for(var i=0;i<=right-left;++i)ind+=(left+i==page?fill[i]:empty[i]);

if(flag)ind+=”…”;

//apply

try{ item=cont.getItemByLabel(“indicator”).setLabel(ind);

}catch(e){

alert(“Item not found. You need to label an item ‘indicator'”);

}

]]>

9 Commentsto Minimalistic page indicator

  1. Anonymous says:

    < ![CDATA[

    Another nice one

    ]]>

  2. Anonymous says:

    < ![CDATA[

    Good job

    ]]>

  3. Anonymous says:

    < ![CDATA[

    Congratulations..

    ]]>

  4. Anonymous says:

    < ![CDATA[

    works fine after i changed it to get the desktop directly and not by using getEvent(). getcontainer(). and please delete the – in the line before var page.

    ]]>

  5. Anonymous says:

    < ![CDATA[

    gerd reuter I prefer to use getevent, but of course you can change it if you are running it from a different action.


    (And I deleted the ‘-‘ thanks. It was from Google+ syntax)

    ]]>

  6. Anonymous says:

    < ![CDATA[

    TrianguloY what will happen (not only in this script) when getevent. getcontainer is not the object you expect? eventually scripterrors. with e. g. LL.getDesktopByName you should get what you want.

    ]]>

  7. Anonymous says:

    < ![CDATA[

    The container from the event is almost always the necessary.


    Sometimes it is not, but I don’t want to use the getdesktopbyname because you will need to specify the name, and the script won’t be ready-to-run.



    Hey, you know how to modify it to be as you want to. That’s the important, the main purpose of my scripts are just to be examples. You may modify them as you want (if you know how). Just share it also if the modification is really interesting 😉

    ]]>

  8. Anonymous says:

    < ![CDATA[

    But, then……


    Wait a moment gerd reuter.


    You said you needed to modify this script to select the correct desktop…but why?


    I mean: you need to set it to run in the changeposition event of a container, the container of which you want to have the indicator.


    I can understand some other scripts, but in this case if the container is not the one you want, it is because you set it in the wrong container! Am I wrong? Maybe I’m missing something…please let me know (this will also help me to make more universal scripts 🙂

    ]]>

  9. Anonymous says:

    < ![CDATA[

    TrianguloY i changed it just to get the desktop directly. i like this more then the getevent.getcontainer.

    ]]>

Leave a Reply

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