Page 1 of 1

Middle Click Launcher - need help.

Posted: 29 Oct 2021 10:54
by eil
i made a script for myself that is launched via CEA middle-click, searching trough folders and its subs, showing menu with list of all found exes.

Code: Select all

$exe = ""; $run = ""; $list = "";
 $list = quicksearch("*.exe","<selitem>","|");  
  foreach($token, $list, "|") {
    $exe = $exe . $token . ";" . $token . ";" . $token . "|";
  }
  if ($list != "") {$run = popupmenu(trim($exe, "|", "R"));}  //trim() deletes one very last | added in foreach 
    else {end};
  if ($run != "") {run quote($run);}
Then i wanted to modify it in few ways and got stuck.
1) I'd wish script to somehow remember which exe i did select last time and sort that on top of list/menu, but realization..
1.1) Use permanent variable and store all selected exes there, checking each time and sorting menu if token is found - but obviously at some point variable will reach it's limit(though i'm not sure what is the exact limit).
1.2) Use labels, marking all selected exes with special label and checking on search for menu - but that will start to fill system with basically useless labelled files here and there.

2) As some folders have quite deep nested structure, forming of menu takes some seconds, and I'd wish to add some "caсhe"-ability, to not mess with searching each time and simply take data from "cache" - but this idea again "crashes" with variable(permanent) limits, that would be overflown fast, if storing whole lists of exes.

Not asking to write some code, just any ideas and thoughts would be appreciated.

Re: Middle Click Launcher - need help.

Posted: 29 Oct 2021 11:31
by highend
Just use a file to store / cache your files? Imho it doesn't make sense to try to cache something because you need to add cache management abilities and how do you know when the cache is stale?

The last used file can reside in a perm if necessary...

Putting something on top of a string?
Escape the file to put on top via a regex, remove the file (and all of it's occurrences) via a regexreplace() and afterwards concatenate the file and the rest of the menu...

And regarding the existing script...

Code: Select all

    $menu  = "";
    $files = quicksearch("*.exe", <selitem>);
    foreach($file, $files, <crlf>, "e") {
        $menu .= $file . "|" . $file . "|" . $file . <crlf>;
    }
    if ($menu) {
        $sel = popupmenu($menu, 6:=<crlf>, 7:="|");
        if ($sel) { run quote($sel); }
    }
You don't need to initialize variables that will be filled by a function, you don't need to quote XY internal variables, more modern concatenation, more readable variable names and the most important thing: easier to debug (because of using <crlf> as a separator) + your version runs into a problem if a path or file name contains a ";"

Re: Middle Click Launcher - need help.

Posted: 30 Oct 2021 01:29
by eil
highend wrote: ↑29 Oct 2021 11:31 Just use a file to store / cache your files?
I specifically didn't mention using file, as it's nothing better than making actual search, plus same I/O operations each time - while i was looking for a way to lessen real hdd reads and use "virtual storage" variable with loaded list of menus that were already searched-created before, and fast to check as a pile of text.
highend wrote: ↑29 Oct 2021 11:31 Imho it doesn't make sense to try to cache something because you need to add cache management abilities and how do you know when the cache is stale?
This script is created mainly for fast launch of exes in apps folders without diving inside, state of such locations(or at least exes themselves) doesn't really change.

Thank you for script organizing advices.
highend wrote: ↑29 Oct 2021 11:31 you don't need to quote XY internal variables
If that's about
run quote($run);
then it's just a habit in case there are spaces in names.
highend wrote: ↑29 Oct 2021 11:31 easier to debug (because of using <crlf> as a separator) + your version runs into a problem if a path or file name contains a ";"
If that's about
$exe = $exe . $token . ";" . $token . ";" . $token . "|";
then i just follow Help file syntax:
popupmenu("Something with Folder Icon;Now *.<DIR> shows the folder icon.;*.<DIR>");
As i understood, between name, icon and path there Must be a ; for menu to use this parameters - if i'm wrong , then Help file misleads.

Re: Middle Click Launcher - need help.

Posted: 30 Oct 2021 09:47
by highend
I specifically didn't mention using file, as it's nothing better than making actual search, plus same I/O operations each time - while i was looking for a way to lessen real hdd reads
As long as your perms don't need to survive a session? Otherwise you'd have at least the same I/O as with a file

run quote($run);
That's not even an internal XY variable...

"<selitem>"^^
As i understood, between name, icon and path there Must be a ; for menu to use this parameters
There is nothing misleading for that command, not every popupmenu is about files / paths. It has the necessary arguments to change the defaults

Re: Middle Click Launcher - need help.

Posted: 02 Nov 2021 09:22
by eil
highend wrote: ↑30 Oct 2021 09:47 As long as your perms don't need to survive a session? Otherwise you'd have at least the same I/O as with a file
If i'm correct, pem-vars are read only once on start of XY and written in end(or forcefully on writepv), while using file would require reading it each time script is used and writing after each new location = looks like much more I/O.
highend wrote: ↑30 Oct 2021 09:47 run quote($run);
That's not even an internal XY variable...

"<selitem>"^^
Yeap, my bad, understood it next morning. Still it worked so no harm.
highend wrote: ↑30 Oct 2021 09:47
As i understood, between name, icon and path there Must be a ; for menu to use this parameters
There is nothing misleading for that command, not every popupmenu is about files / paths. It has the necessary arguments to change the defaults
Examples are misleading, because both show only usage with default ";". Yet, i didn't even expect such separators could be changed, as i know no other command allowing such changes.

Anyway, i improved script and maybe will upload it in Script section, thank you for some hints.

Re: Middle Click Launcher - need help.

Posted: 02 Nov 2021 10:08
by highend
If i'm correct, pem-vars are read only once on start of XY and written in end(or forcefully on writepv), while using file would require reading it each time script is used and writing after each new location = looks like much more I/O.
The script should do the same on each run (writing it out via writepv), otherwise (if OS / XY malfunctions / crashes), you'll lose what the script captured on last run
Yet, i didn't even expect such separators could be changed
That's why there is a syntax definition before everything else^^
as i know no other command allowing such changes
oO
colorfilter, favs, folderreport, formatlist, several get subcommands, etc., etc.

Re: Middle Click Launcher - need help.

Posted: 02 Nov 2021 13:07
by eil
highend wrote: ↑02 Nov 2021 10:08
as i know no other command allowing such changes
oO
colorfilter, favs, folderreport, formatlist, several get subcommands, etc., etc.
You're saying about separators as a whole, i was saying about exactly these "second level separators" in popupmenu. Almost everywhere XY has a strict syntax and order, so when examples show only default variant it's obvious that non-programmer users will take it as a "must".(just explaining why even mentioning smth in command description may be not enough)