why this script don't work?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
k20
Posts: 3
Joined: 13 Jan 2026 06:06

why this script don't work?

Post by k20 »

Right-click on line number > Run Script

Code: Select all

$sel = get("SelectedItemsPathNames");
if ($sel == "") { msg "No file selected."; exit; }
$numSel = count(split($sel, "\n"));

// Build menu manually as here-doc-like string (safe)
$menu = "";

// Define apps: [name, exe, mode]
@entries = (
    ["Notepad++", "<xydrive>\\Portables\\~Viewers\\notepad++\\notepad++.exe", "any"],
    ["ImHex", "<xydrive>\\Portables\\~Viewers\\ImHex\\ImHexPortable.exe", "single"]
);

foreach ($entry in @entries) {
    $name = $entry[0];
    $exe = $entry[1];
    $mode = $entry[2];

    if (!exists($exe)) { continue; }
    if ($mode == "single" && $numSel > 1) { continue; }

    // Escape backslashes for safety (though usually not needed)
    // Use single quotes inside run '' to avoid escaping
    $cmd = "run '" . $exe . " <selitems>'";
    $menu .= $name . "|" . $cmd . "|" . $exe . "\n";
}

if ($menu == "") {
    msg "No apps available.", "POM";
    exit;
}

 $chosen = popupnested($menu,,,,,,,|);
 if ($chosen != "") {
      load $chosen,, s;
}

RalphM
Posts: 2054
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: why this script don't work?

Post by RalphM »

Where does the @entries come from? :whistle:
Ralph :)
(OS: W11 24H2 Home x64 - XY: Current x32 beta - Office 2024 32-bit - Display: 1920x1080 @ 125%)

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

Re: why this script don't work?

Post by highend »

Ask that the AI that created it and tell her to not hallucinate...
One of my scripts helped you out? Please donate via Paypal

k20
Posts: 3
Joined: 13 Jan 2026 06:06

Re: why this script don't work?

Post by k20 »

Yes! Is from AI... I update my script.
I padding each line in the script from the beggining with " ". Works!
The script runs... but stop at "Invalid Parameter: $entry as $entries" ...

Code: Select all

       $sel = get("SelectedItemsPathNames");
       if ($sel == "") { msg "No file selected."; exit; }
       $numSel = count(split($sel, "\n"));

       // Define apps: [name, exe, mode]
       $entries = array(
           array("Notepad++", "<xydrive>\\Portables\\~Viewers\\notepad++\\notepad++.exe", "any"),
           array("ImHex", "<xydrive>\\Portables\\~Viewers\\ImHex\\ImHexPortable.exe", "single")
       );
       
       // Build menu manually as here-doc-like string (safe)
       $menu = "";

       foreach ($entry as $entries) {
           $name = $entry[0];
           $exe = $entry[1];
           $mode = $entry[2];
       
           if (!exists($exe)) { continue; }
           if ($mode == "single" && $numSel > 1) { continue; }
       
           // Escape backslashes for safety (though usually not needed)
           // Use single quotes inside run '' to avoid escaping
           $cmd = "run '" . $exe . " <selitems>'";
           $menu .= $name . "|" . $cmd . "|" . $exe . "\n";
       }
       
       if ($menu == "") {
           msg "No apps available.", "POM";
           exit;
       }
       
       $chosen = popupnested($menu,,,,,,,|);
       if ($chosen != "") {
           load $chosen,, s;
       }

k20
Posts: 3
Joined: 13 Jan 2026 06:06

Re: why this script don't work?

Post by k20 »

working code:

Code: Select all

    // Get count to check for 'single' mode logic
    $numSel = get("CountSelected");
    if ($numSel == 0) { echo "No file selected."; }

    // Use native array as requested
    $entries = array(
        "Notepad++|<xydrive>\Portables\~Viewers\notepad++\notepad++.exe|any",
        "ImHex|<xydrive>\Portables\~Viewers\ImHex\ImHexPortable.exe|single"
    );

    $menu = "";

    // Iterate through the array
    foreach ($entries as $item) {
        $name = gettoken($item, 1, "|");
        $exe  = gettoken($item, 2, "|");
        $mode = gettoken($item, 3, "|");

        if (!exists($exe)) { continue; }
        if ($mode == "single" && $numSel > 1) { continue; }

        // Use <selitems> to pass multiple files to the executable
        $cmd = "run " . quote($exe) . " <selitems>";
        $menu .= $name . ";" . $cmd . ";" . $exe . "|";
    }

    if ($menu == "") { echo "No apps available."; }

    // popupnested(menu, [x], [y], [width], [height], [heading], [separator], [item_separator])
    $command = popupnested($menu, , , , , , "|", ";");
    if ($command != '') { 
        load $command, , "s"; 
    }
the script works but i receive an error\warning: Dubious syntax: "<xydrive>\Portables\~Viewers\notepad++\notepad++.exe" "D:\test1.txt" "D:\test2.txt"
Press continue and the command runs ok. If i disable "Script > Syntax Checking" the script runs without warnings..
Sorry my english!

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

Re: why this script don't work?

Post by highend »

Use eval() to resolve the xy variable and fix the quoting?

@Don
Is it intended, that variables in arrays aren't resolved as long as they are used either natively or in double quotes?
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 65382
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: why this script don't work?

Post by admin »

highend wrote: 14 Jan 2026 13:16 @Don
Is it intended, that variables in arrays aren't resolved as long as they are used either natively or in double quotes?
Not really. Fixed in next beta.

Post Reply