Page 1 of 1
number of selected items
Posted: 08 Sep 2008 03:02
by Muroph
i need a script to find out how many items are selected.
i've tried lots of things, but none of them worked.
can anybody help me?
Re: number of selected items
Posted: 08 Sep 2008 10:45
by jacky
Yep, there no variable for this yet. This should do it (note that it uses the clipboard) :
Code: Select all
// Copy Name(s)
focus l;
#102;
set $list, <clipboard>;
// get last 2 chars, crlf means more than one item
substr $fix, $list, -2;
// nothing at all: we'll add 0 (just like when crlf)
regexreplace $fix, $fix, "^$", ":";
// turn crlf into ":"
regexreplace $fix, $fix, <crlf>, ":";
// if everything but ":" it means no crlf (and no empty), so it was one single name, so we'll add 1
regexreplace $fix, $fix, "^[^:]+$", "1";
// otherwise we'll add 0
regexreplace $fix, $fix, "^:$", "0";
//
// turn all crlf in ":"
regexreplace $list, $list, <crlf>, ":";
// remove everything but ":"
regexreplace $list, $list, "[^:]", "";
// thus we get the number of ":" = crlf = items
strlen $nb_items, $list;
// adding the fix
incr $nb_items, $nb_items, $fix;
// results
msg "$nb_items item(s) selected";
Re: number of selected items
Posted: 08 Sep 2008 11:19
by admin
jacky wrote:Yep, there no variable for this yet. This should do it (note that it uses the clipboard) :
Code: Select all
// Copy Name(s)
focus l;
#102;
set $list, <clipboard>;
// get last 2 chars, crlf means more than one item
substr $fix, $list, -2;
// nothing at all: we'll add 0 (just like when crlf)
regexreplace $fix, $fix, "^$", ":";
// turn crlf into ":"
regexreplace $fix, $fix, <crlf>, ":";
// if everything but ":" it means no crlf (and no empty), so it was one single name, so we'll add 1
regexreplace $fix, $fix, "^[^:]+$", "1";
// otherwise we'll add 0
regexreplace $fix, $fix, "^:$", "0";
//
// turn all crlf in ":"
regexreplace $list, $list, <crlf>, ":";
// remove everything but ":"
regexreplace $list, $list, "[^:]", "";
// thus we get the number of ":" = crlf = items
strlen $nb_items, $list;
// adding the fix
incr $nb_items, $nb_items, $fix;
// results
msg "$nb_items item(s) selected";
Wow. I think it's time for the
getinfo command...

Re: number of selected items
Posted: 08 Sep 2008 15:17
by Muroph
thanks guys!
but i did it myself in the end.
nothing like a good night of sleep (and boring classes

) to help you think, huh?
Code: Select all
focus;
#201;
regexreplace $num, "<clipboard>", "[^:]",;
strlen $num, "$num";
looks like it has something in common with jacky's script.
but the script i want to use it for will paste the items, so i used #201.
then its just a matter of counting how many colons are on the clipboard.
it will return "1" even if there's nothing selected, but it works for what i need it.
EDIT:
this works perfectly
Code: Select all
focus;
//copy names
#102;
set $num, "<crlf><clipboard>";
//this will get rid of the <crlf> at the end of the string. if nothing is selected it will return an empty string
regexreplace $num, "$num", "<crlf>$",;
//replace <crlf> with ":", delete everything else and count the colons
regexreplace $num, "$num", "<crlf>", :;
regexreplace $num, "$num", "[^:]",;
strlen $num, "$num";
msg "$num items";
Re: number of selected items
Posted: 08 Sep 2008 18:51
by serendipity
admin wrote:Wow. I think it's time for the
getinfo command...

Yes please, I will use this too.