Thank you so much for reviving my script, Mathias ! Sorry to trouble you, but can you tell me why this particular script is failing (I'm guessing it's the ArrayFind)?
I get the following errors:
2026-05-06 11:22:54.288 Script engine error => Failed to process token - "$rules"
2026-05-06 11:22:54.288 Script engine error => Failed to initialize variable "$rules" with "
2026-05-06 11:22:54.288 Script engine error => Failed to define variable - "@var $rules[] ="
2026-05-06 11:22:54.288 Script engine error - Line : 11, Error : -1 => Code : "@var $rules[] ="
Here's the full code:
@var $path = GetSourceFocusPath();
@var $ext = StrToLower( PathGetFileExtPart( $path, 2 ) );
@var $textExts[] = {'txt','ini','log','ahk','mtxt','vbs','conf','cpp','h','rc','asm','nfo','info','ps1','xml','jsee','cfg'};
@var $imageExts[] = {'jpg','jpeg','jpe','jfif','png','gif','webp','bmp','tiff','psd','svg'};
@var $docExts[] = {'pdf','epub','djvu','mobi','fb2','cb7','cbr','cbt','cbz','prc','azw'};
@var $kegaExts[] = {'sms','gen','smd','bin','md'};
@var $snesExts[] = {'sfc','smc','fig'};
@var $audioExts[] = {'wav','mp3','mid','midi','wma','flac','ogg','aac','alac','aiff'};
@var $cursorExts[] = {'cur','ani'};
@var $rules[] =
{
{'udc', $textExts, 'b85b4bf468ab418e87b4e09e95dca4a0'},
{'udc', $imageExts, 'c3424b15b3dd4a75a83ce0d9ba857bbb'},
{'udc', $docExts, '3bd046dd55484d62aa82285076ea1c15'},
{'udc', {'zip'}, 'e271faf8469f4e96ac335fde319ab818'},
{'udc', {'chm'}, '45cd3dfb7fc348ec99de80122481c55d'},
{'udc', $kegaExts, '468167006ee54bb995e28940823ec958'},
{'udc', $snesExts, '6d1061dff5014030bcd2062fee6701cf'},
{'udc', {'nes'}, '3d966becbbb640f983aab1f18a109f51'},
{'udc', $audioExts, '4e1f3a7ca0224c6ba0ff02f3f07cd7c4'},
{'udc', $cursorExts, '3c16c3020c384373a4dd96060cb856e3'},
{'run', {'pptx'}, '"C:\\Program Files\\Microsoft Office\\root\\Office16\\POWERPNT.EXE"', '/S "{$path}"'},
{'run', {'ppt'}, '"C:\\Program Files\\Microsoft Office\\root\\Office16\\POWERPNT.EXE"', '"{$path}"'},
{'run', {'sln'}, '"D:\\Download\\VS 19 CE\\Common7\\IDE\\devenv.exe"', '"{$path}"'},
{'udc', {'exe'}, 'e07317b5406b4c19b069ea4bd926f706'}
};
@var $matched = 0;
foreach( $rule in $rules)
{
if( arrayIFind( $rule[1], $ext ) > -1 )
{
$matched = 1;
if( $rule[0] == 'udc' )
{
MC.RunUserCmd ID=$rule[2];
}
else if( $rule[0] == 'run' )
{
MC.Run CMD=$rule[2] ARG=$rule[3];
}
break;
}
}
if( $matched == 0 )
{
MessageBox( "SmartOpen", "No handler defined for extension: ." + $ext, 0 );
}
P.S: Nevermind, the arrays definition is probably the issue, I'm using my old code… P.P.S: Nevermind I figured it out, switched from For Loop to ForEach Loop. changed the For part "for( $i = 0; $i < 14; $i++ )" to "foreach( $rule in $rules)" and commented out "$rule = $rules[$i];" and also commented out both "@var $i;" and "@var $rule;" !
foreach may be slightly faster in theory because it bypasses manual index increment and bounds checking, but the gain is microseconds at most.
ForEach couldn't handle certain cases, had to switch to Arrays + IF's.