Author Topic: [HELP] Dynamic File Extension-Based Execution Script (Possible Implementation ?)  (Read 51 times)

total_annihilation00

  • Active Member
  • ***
  • Posts: 129
  • Tech Savant\ Envisioneering
    • View Profile
I'am attempting to develop a script that dynamically executes files based on their extensions, bypassing the default file type associations. For example, I want to open *.ZIP files with 'FBNeoX' (game ROM emulator software) instead of the standard 'WinRar' as configured in File Type Settings et. al.. The goal is to trigger specific applications to open files with certain extensions through a custom script when the file is focused (separate from File Type Settings.)

I've experimented with AI-generated scripts and implemented multiple conditional statements (if/else), but I keep encountering errors. I'am wondering if it's feasible to achieve this functionality within MultiCommander via scripting. Is such dynamic extension-based execution achievable in MultiCommander, and if so, what would be the recommended approach ?

This doesn't work (one of many !)::

Code: [Select]
// SmartOpen — Ctrl+F9
// Requires MultiScript modules: Str (String Tools), Path (Path Tools)
@var $f = GetSourceFocusPath();
if ($f == "") { return; }
if (FS.IsFolder($f) == 1) { return; }
// extension (lowercase, without dot)
@var $ext = Path.GetFileExtension($f);   // requires Path module
$ext = Str.LCase($ext);                  // requires Str module
@var $app = "";
// MASM
if      ($ext == "asm") { $app = "D:\\masm32\\qeditor.exe"; }
// Text-like (Markdown intentionally NOT included)
elseif  ($ext == "txt" || $ext == "ini" || $ext == "log" || $ext == "ahk" ||
         $ext == "mtxt"|| $ext == "vbs" || $ext == "conf"|| $ext == "cpp" ||
         $ext == "h"   || $ext == "rc"  || $ext == "nfo" || $ext == "info"||
         $ext == "ps1" || $ext == "xml" || $ext == "jsee"|| $ext == "cfg") {
  $app = "C:\\Users\\dell\\Downloads\\thumbstick\\notepad2-4-2-25-en-win\\Notepad2.exe";
}
// Pictures
elseif  ($ext == "jpg" || $ext == "jpeg"|| $ext == "jpe" || $ext == "png" ||
         $ext == "gif" || $ext == "bmp" || $ext == "tif" || $ext == "tiff"||
         $ext == "webp"|| $ext == "jfif"|| $ext == "psd") {
  $app = "D:\\Download\\FreeVimager\\FreeVimager.exe";
}
// E-books
elseif  ($ext == "pdf" || $ext == "epub"|| $ext == "djvu"|| $ext == "mobi" ||
         $ext == "fb2" || $ext == "cb7" || $ext == "cbr" || $ext == "cbt"  ||
         $ext == "cbz" || $ext == "prc" || $ext == "azw" || $ext == "chm") {
  $app = "C:\\Users\\dell\\Documents\\SumatraALLOld\\SumatraPDF-3.2-64.exe";
}
// Cursors / Icons
elseif  ($ext == "cur" || $ext == "ani") {
  $app = "D:\\Download\\RealWorld Cursor Editor\\RWCursorEditor.exe";
}
// PowerPoint
elseif  ($ext == "pptx"|| $ext == "ppt" || $ext == "pps" || $ext == "ppsx") {
  $app = "C:\\Program Files\\Microsoft Office\\root\\Office16\\POWERPNT.EXE";
}
// Visual Studio
elseif  ($ext == "sln") {
  $app = "D:\\Download\\VS 19 CE\\Common7\\IDE\\devenv.exe";
}
// Sega Genesis / Mega-Drive (.md intentionally included)
elseif  ($ext == "gen" || $ext == "smd" || $ext == "bin" || $ext == "md") {
  $app = "D:\\Games\\Genesis ROMs\\Gens-2.11\\Gens 211 (Hacked) (USETHIS).qalnk";
}
// SNES
elseif  ($ext == "sfc" || $ext == "smc" || $ext == "fig") {
  $app = "D:\\Games\\Genesis ROMs\\SNES 9x Emulator\\SNES 9x x64 Emulator.qalnk";
}
// NES
elseif  ($ext == "nes") {
  $app = "D:\\Games\\Genesis ROMs\\Nestopia140bin\\Nestopia NES Emulator.qalnk";
}
// FB Neo ZIP ROMs
elseif  ($ext == "zip") {
  $app = "C:\\Users\\dell\\Documents\\FB Neo x64 (DO NOT DELETE)\\fbneo64.exe";
}
// Launch (ShellExecute works for .exe and .qalnk)
if ($app == "") {
  MC.ShellExecute FILE="{$f}" SHOW=1;
} else {
  MC.ShellExecute FILE="{$app}" PARAMS="\"{$f}\"" SHOW=1;
}

OR THIS::

Code: [Select]
// SmartOpen (Ctrl+F9) — Multi Commander v15.6
// Opens the focused file in a designated app by extension
@var $item = GetSourceFocusPath();
if ($item == "") { return; }         // nothing focused
if (FS.IsFolder($item) == 1) { return; }  // ignore folders
@var $ext = Str.LCase(Path.GetFileExt($item));  // extension without dot (lowercase)
@var $app = "";
// Text-like
if ( $ext == "txt"  || $ext == "ini" || $ext == "log" || $ext == "ahk" ||
     $ext == "mtxt" || $ext == "vbs" || $ext == "conf"|| $ext == "cpp" ||
     $ext == "h"    || $ext == "rc"  || $ext == "asm" || $ext == "nfo" ||
     $ext == "info" || $ext == "ps1" || $ext == "md"  || $ext == "xml" ||
     $ext == "jsee" || $ext == "cfg" ) {
  $app = "C:\Users\dell\Downloads\thumbstick\notepad2-4-2-25-en-win\Notepad2.exe";
// Pictures
} else if ( $ext == "jpg" || $ext == "png"  || $ext == "jpeg" || $ext == "gif" ||
            $ext == "webp"|| $ext == "jpe"  || $ext == "jfif" || $ext == "psd" ||
            $ext == "bmp" || $ext == "tif"  || $ext == "tiff" ) {
  $app = "D:\Download\FreeVimager\FreeVimager.exe";
// e-Books
} else if ( $ext == "pdf" || $ext == "epub" || $ext == "djvu" || $ext == "mobi" ||
            $ext == "fb2" || $ext == "cb7"  || $ext == "cbr"  || $ext == "cbt"  ||
            $ext == "cbz" || $ext == "prc"  || $ext == "azw"  || $ext == "chm" ) {
  $app = "C:\Users\dell\Documents\SumatraALLOld\SumatraPDF-3.2-64.exe";
// Cursors / Icons
} else if ( $ext == "cur" || $ext == "ani" ) {
  $app = "D:\Download\RealWorld Cursor Editor\RWCursorEditor.exe";
// PowerPoint
} else if ($ext == "pptx") {
  $app = "C:\Program Files\Microsoft Office\root\Office16\POWERPNT.EXE";
// Visual Studio Solutions
} else if ($ext == "sln") {
  $app = "D:\Download\VS 19 CE\Common7\IDE\devenv.exe";
} else {
  // No handler for this extension
  return;
}
// Launch the app with the focused file as argument
App.Run CMD="$app" PARAMS="\"$item\"" SHOW=1 WAIT=0;

P.S: *.QALNK filetypes are just special types of shortcuts I use to Run as Admin, effectively bypassing UAC Prompts (using the "Quick Admin" app.) Apparently you need to use ShellExecute to open *.QALNK files in MC & stuff…
« Last Edit: Today at 12:28:59 by total_annihilation00 »
~The World's Deceit Has Raped My Soul, We Melt The Plastic People Down Then We Melt Their Plastic Town~


Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4787
    • View Profile
    • Multi Commander
I think it should be possible.. what error do you get?

Maybe start with checking just one file extension , one if/else part then then build it up with more..


Hm "elseif" I dont think is supported..  I think it must be "else if"  two words
and Boolean operator like || is not supported..
Create a method that return true/false..  and in that you check for wanted extensions..

function IsTextFile($ext)
{
  if( $ext == "txt" ) { return true; }
  if( $ext == "nfo" ) { return true; }
  if( $ext == "cfg" ) { return true; }
  return false;
 }

if( IsTextFile($ext) )
{
  // open as text file
}

« Last Edit: Today at 14:54:48 by Mathias (Author) »

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4787
    • View Profile
    • Multi Commander
I got AI to generate valid MultiScript. But you need to make sure the AI knows how MultiScript works firsts.
Like either linking to all the pages and examples on the documentation page or copy and paste that information into a document that you include to the LLM.


total_annihilation00

  • Active Member
  • ***
  • Posts: 129
  • Tech Savant\ Envisioneering
    • View Profile
I think it should be possible.. what error do you get?

Maybe start with checking just one file extension , one if/else part then then build it up with more..


Hm "elseif" I dont think is supported..  I think it must be "else if"  two words
and Boolean operator like || is not supported..
Create a method that return true/false..  and in that you check for wanted extensions..

function IsTextFile($ext)
{
  if( $ext == "txt" ) { return true; }
  if( $ext == "nfo" ) { return true; }
  if( $ext == "cfg" ) { return true; }
  return false;
 }

if( IsTextFile($ext) )
{
  // open as text file
}


Yes I don't know how to do the Run part, otherwise I'd give it a go ! P.S: Nvm I had the code for MC.Run. Anyway I get false and Parse error. I'll try a few more times…
« Last Edit: Today at 18:21:09 by total_annihilation00 »
~The World's Deceit Has Raped My Soul, We Melt The Plastic People Down Then We Melt Their Plastic Town~