Script Selector

Discuss and share scripts and script files...
Post Reply
kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Script Selector

Post by kiwichick »

Hi there, I've been checking out Stefan's Script Selector here:

http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=5350

I love it!!! It's an awesome idea!!! The thread is a couple of years old so there may be some outdated code in it because, when selecting multiple scripts, it doesn't run the last script.
Windows 10 Pro 22H2

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Script Selector

Post by highend »

Replace everything from
//Depending if one or more script is selected
till the end of the script with this:

Code: Select all

      //Depending if one or more script is selected:
      IF ($CountScriptsToExecute>1)
      {
          //execute several scripts:
          while(true)
          {
          
          //ToDo: maybe "IF (strpos($array, "|") == -1) { execute last script without ask for}
          
            $cript = inputselect("You choose several scripts<crlf>
                                 select next script to execute",$array,,2);
            
            //drop the comment part:
            $criptWC = regexreplace($cript, "^(.+) - .+(\|)*$", "$1");
            
            msg "Multi: " $criptWC,1; 
            //text readfile("<xyscripts>\" . $cript . ".xys"); 
            //load $cript; 
            
            //clean up the array:
            $array = replace($array, $cript);
            $array = regexreplace($array, "^\|(.+)", "$1");
            $array = replace($array, "||");
            $array = regexreplace($array, "^\|$");
            IF ($array==""){break;}

            //this script waits till the called script is finished.
            
          }
      }else
      {
          //execute single script only:
          $cript = gettoken($array, 1, "|");
          //drop the comment part:
          $cript = regexreplace($cript, "(.+) -.+", "$1");
          msg "Single: " $cript,1; 
          //text readfile("<xyscripts>\" . $cript . ".xys"); 
          //load $cript; 
      }
    }
And please use the original thread if you have a problem with a specific script...
One of my scripts helped you out? Please donate via Paypal

kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: Script Selector

Post by kiwichick »

Thanks once again highend, I'll check this out. Sorry about not using the original thread - it was so old and had no other comments that I wasn't sure I was allowed to :oops:
Windows 10 Pro 22H2

j_c_hallgren
XY Blog Master
Posts: 5826
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Script Selector

Post by j_c_hallgren »

kiwichick wrote: Sorry about not using the original thread - it was so old and had no other comments that I wasn't sure I was allowed to :oops:
There is no age limit on threads here, either by software or user consensus, so we don't mind an old thread being revived IF it applies directly/specifically to the issue.
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: Script Selector

Post by kiwichick »

Thanks j_c_hallgren, I know the thread didn't specifically say so but sometimes they're 'locked' and posting isn't allowed. And it was such a great piece of script I couldn't see why there wouldn't be some kind of discussion going on unless it wasn't allowed lol.

And sorry, highend, but the code you gave me didn't work. From what I can see you renamed one of the regexreplace variables and moved the 'clean up array' section to before the 'drop the comment part' section. The results is a 'Script file xxx not found' error when 'load $cript' is executed. I managed to get it to work by getting rid of the comment part altogether and renaming the regexreplace variable back to its original name. So I've ended up with:

Code: Select all

//generate list of scripts (without sub-folders):    
    //generate an filter to see only wanted scripts:
    $preFilterScripts = input("Prefilter Script by part of
                 file name","Pattern, e.g. rename or B or *C", ,,"");

    //get an list of wanted scripts:
    //(listfolder() needs at least v9.30.0023)
    $myScripts = listfolder("<xyscripts>", "$preFilterScripts*.xys");
    
    //collect the base name without extension into var $myScripts:
    //$myScripts = report("{basename} - ({comment})|",$myScripts);
    $myScripts = report("{basename}|",$myScripts);
    
    //show InputSelect-dialog to select one of those scripts:
    $cripts = inputselect("Select one or more script to execute",$myScripts,,2);
    
    //execute that choosen script(s):
   //(if not inputselect() is cancelled)
    If ($cripts>"")
    {
      //Count the choosen scripts:
      $Loop=1;
      $CountScriptsToExecute=0;
      $array="";
      while(true)
      {
        $cript = gettoken($cripts, $Loop, "|");
        IF ($cript==""){break;}
        $array = $array . $cript ."|";
        incr $CountScriptsToExecute;
      incr $Loop;
      }
      
      //Depending if one or more script is selected:
      IF ($CountScriptsToExecute>1)
      {
          //execute several scripts:
          while(true)
          {
         
          //ToDo: maybe "IF (strpos($array, "|") == -1) { execute last script without ask for}
         
            $cript = inputselect("You choose several scripts<crlf>
                                 select next script to execute",$array,,2);
           
            //drop the comment part:
            //$criptWC = regexreplace($cript, "^(.+) - .+(\|)*$", "$1");
           
            msg "Multi: " $cript,1;
            //text readfile("<xyscripts>\" . $cript . ".xys");
            load $cript;
           
            //clean up the array:
            $array = replace($array, $cript);
            $array = regexreplace($array, "^\|(.+)", "$1");
            $array = replace($array, "||");
            $array = regexreplace($array, "^\|$");
            IF ($array==""){break;}

            //this script waits till the called script is finished.
           
          }
      }else
      {
          //execute single script only:
          $cript = gettoken($array, 1, "|");
          //drop the comment part:
          //$cript = regexreplace($cript, "(.+) -.+", "$1");
          msg "Single: " $cript,1;
          //text readfile("<xyscripts>\" . $cript . ".xys");
          load $cript;
      }
    }
And sorry everyone if, again, I should have posted back to the original. I feel like I've totally mucked it up now :oops:
Windows 10 Pro 22H2

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Script Selector

Post by highend »

load $criptWC;

instead of load $cript;

should have been enough to let it work.
One of my scripts helped you out? Please donate via Paypal

kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: Script Selector

Post by kiwichick »

Thanks highend, I didn't think of that. I didn't want the comments included anyway so I'm pleased I figured out how to get rid of them.
Windows 10 Pro 22H2

Post Reply