Page 1 of 2
Toggle floating preview script help
Posted: 05 Jul 2017 15:44
by fogg
Hello! I am running the floating preview in my script but floating preview closes after each one time!
My script is select one file and floating preview and open this file in notepad. And again select the next file when I exit the notepad.
Re: scripting floating preview bug
Posted: 05 Jul 2017 15:47
by bdeshi
How are you running floating preview in your script?
Re: scripting floating preview bug
Posted: 05 Jul 2017 15:53
by fogg
It is my script
Code: Select all
$NUMBER = 56;
$LOOP = 0;
while($LOOP < $NUMBER){
$LOOP++;
sel $LOOP;
#178; // it is floating preview code at help | list all commands
run "notepad <curitem>",,1,1;
}
I run script with Menu >Script >Run Script
Re: scripting floating preview bug
Posted: 05 Jul 2017 16:01
by highend
This is no bug. It toggles fp on / off.
Regarding your script and to handle it correctly:
You can get the state of fp with
0 = FP not active
1 = FP active
So you only need to execute it on the first item
and execute it again after the loop is done
I've moved the topic...
Re: Toggle floating preview script help
Posted: 05 Jul 2017 16:12
by fogg
Thankyou!!!
Now it is my script. All ok!
Code: Select all
$state = get("#178");
if($state==1){ #178; // it is floating preview code at help | list all commands}
$NUMBER = 56;
$LOOP = 0;
while($LOOP < $NUMBER){
$LOOP++;
sel $LOOP;
run "notepad <curitem>",,1,1;
}
$state = get("#178");
if($state==1){ #178; // it is floating preview code at help | list all commands}
Re: Toggle floating preview script help
Posted: 05 Jul 2017 16:21
by bdeshi

@fogg: It's wokring yes, but
accidentally. You're missing two pieces of the puzzle
1.) You've commented out an important bit: the } at the end of the if clause.
Code: Select all
$state = get("#178");
if($state==1){ #178; // it is floating preview code at help | list all commands}
2.) Also, you have to check if the FP is NOT open and open it in this case.
$state==1 means the FP is
already open - #178 will now toggle it off. So your code when corrected will never show the FP!
So, all in all, use this instead:
Code: Select all
$state = get("#178"); // get FP status. 1 is open, 0 is closed
if ($state==0) { // $state==0 means floating preview is NOT active.
#178; // #178 opens it in that case.
}
$NUMBER = 56;
$LOOP = 0;
while ($LOOP < $NUMBER) {
$LOOP++;
sel $LOOP;
run "notepad <curitem>",,1,1;
}
#178; // since FP is sure to be open at this point, this will toggle it off.
fogg wrote:I've moved the topic...
got me mildly panicking a bit there! I was typing a response and submitted only to get ~"the topic does not exist".
Re: Toggle floating preview script help
Posted: 06 Jul 2017 08:21
by fogg
Thank you too!!!

This script also work. I use your script now.
SammaySarkar wrote: I've moved the topic...
got me mildly panicking a bit there! I was typing a response and submitted only to get ~"the topic does not exist".
BUt i didnot move the topic!
Re: Toggle floating preview script help
Posted: 06 Jul 2017 08:26
by fogg
Also i want help to automactic count number of files? Now I write $NUMBER=56 when 56 files and other number for other files. I wish like this:
???
Re: Toggle floating preview script help
Posted: 06 Jul 2017 08:46
by highend
Count which files, all existing
or e.g. only txt files?
Code: Select all
$NUMBER = listfolder(, "*.txt", 1+32);
Re: Toggle floating preview script help
Posted: 06 Jul 2017 09:47
by bdeshi
counting items: I believe you are looking for item count to run the while loop on them to
select and run in notepad. You'd better use the items' full paths instead of blind list indexes (in case list might have other items besides your to-preview files). Try something like this:
Code: Select all
$ITEMS = listpane(, "*.txt", 1); // |-separated list of only pdf files in list.
foreach ($ITEM, $ITEMS) { // walk thru each item on the $ITEMS list
selectitems($ITEM, 2); // select $ITEM. unlike sel, selectitems can select by full path
if (get("#178")==0) { #178; } // open FP. get("#178")==0 means floating preview is NOT active. #178 opens it.
run "notepad ""$ITEM""",,1,1; // open notepad. note the doublequotes around $ITEM. the fullpath can have spaces
}
#178; // since FP is sure to be open at this point, this will toggle it off
This will get a list of all txt files in current list (adjust pattern in listpane() to fit your needs), and loop thru only these files, selecting and opening in notepad.
(Also, I moved the floating preview opening logic after the selection statement, because I discovered the FP won't open if there happens to be no valid selection before the script starts.)
HTH.
--- ---
fogg wrote:SammaySarkar wrote: I've moved the topic...
got me mildly panicking a bit there! I was typing a response and submitted only to get ~"the topic does not exist".
BUt i didnot move the topic!
Sorry I meant to say that to highend.
Re: Toggle floating preview script help
Posted: 06 Jul 2017 09:58
by highend
@Sammay
Do you really think he wants to open .pdf files in standard Windows notepad?

Re: Toggle floating preview script help
Posted: 06 Jul 2017 10:29
by bdeshi
heh!

Ii think I was just copying your post.
Re: Toggle floating preview script help
Posted: 06 Jul 2017 10:39
by highend
It occurred to me that he was probably not attempting to open those files so I changed it a minute later

Re: Toggle floating preview script help
Posted: 06 Jul 2017 10:43
by bdeshi
Well,
fogg wrote:select one file and floating preview and open this file in notepad.
I'm not exactly sure what's the purpose of the script: opening the same file in the FP and notepad? What does this accomplish?

Re: Toggle floating preview script help
Posted: 06 Jul 2017 10:59
by highend
No clue but hey, it's his script...