Open with menu for unknown file-types

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
WirlyWirly
Posts: 195
Joined: 21 Oct 2020 23:33
Location: Through the Looking-Glass

Open with menu for unknown file-types

Post by WirlyWirly »

I use xy's File Association for every common file-type. It works great, I have no issues.

That said, when I access a file-type that has no association, I am presented with this generic explorer menu...

Image

Like xy, just about every program on my computer is portable and so this menu never has the options I'm looking for. Therefore I'd like to over-ride this explorer menu with a custom menu that has a list of programs that I've picked, as well as a "Look for another app on this PC" option in-case I need an external program that's not on that list.

I know xy has it's own right-click "Open with" option, but that only displays the programs associated with the file-type, therefore it's pretty useless for unknown file-types that have no association. A lot of the unknown file-types I run into are linux files, which have no extension since they're not necessary on a linux machine.

I believe the only way to make a custom open-with menu that will popup whenever an unknown file-type is launched would be through scripting. The problem is that I haven't been able to figure out how to capture unknown file-types in the File Association menu, nor am I able to load a script instead of a .exe.

I tried this syntax in File Association, which does capture everything, but that becomes a problem for .exe files and possibly others...

Code: Select all

"Unknown FileType";*><xyscripts>\UnknownFileTypesMenu.xys
This is my current script that I would like to use as an "Open with" menu, still haven't figured out the "Look for another app on this PC" part though...

Code: Select all

/*

An "Open with" menu alternative to the built-in explorer option
$menu = <<<MENU

How do you want to open this file?
0) Vim|run lax("<xypath>..\..\GitPortable\Wrapper-Vim.exe" <selitems>)|"<xypath>..\..\GitPortable\Wrapper-Vim.exe"
1) MediaInfo|run lax("<xypath>..\..\MediaInfoPortable\MediaInfoPortable.exe" <selitems>)|"<xypath>..\..\MediaInfoPortable\MediaInfoPortable.exe"
2) MPC-BE|run lax("<xypath>..\..\MPC-BEPortable\MPC-BEPortable.exe" <selitems>)|"<xypath>..\..\MPC-BEPortable\MPC-BEPortable.exe"
-
3) Look for another app on this PC

MENU;

    // Get X/Y position of a control
    $position = controlposition('TAB 1', 0);
    $x_pos = gettoken($position, 1, '|');
    $y_pos = gettoken($position, 2, '|');

    // Display the context menu
    $command = popupnested($menu, $x_pos, $y_pos,,,,,|);

    // Run the selected command or skip if it uses an id #
    if ($command && !regexmatches($command, '^\#\d+$')) { load $command,, s; }
To sum it up I have 2 issues; I can't figure out how to load a script from the File Association menu and I can't find a syntax for the File Association menu that will only pickup unknown file-types.

Can anyone shed some light on how I might go about getting this to work?
Last edited by WirlyWirly on 23 Nov 2021 06:40, edited 1 time in total.

jupe
Posts: 2757
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Open with menu for unknown file-types

Post by jupe »

I think to do what you want properly you'd have to pass ALL filetypes to your script via CFA (ie. a catchall), then in the script have a list of filetypes you want it to run automatically, (eg. exe) and perform that action on them, then filter the known ones and pass them to which ever app/script you want, then the leftovers are unknown filetypes to be dealt with accordingly, alternatively you can just make your "Unknown Filetype" CFA not auto invoke, by prefixing a pipe char in the CFA listing (as documented in the help file) then when you encounter an unknown filetype you just invoke the OpenWith menu manually and choose Unknown Filetype, or if you mainly just want to catch files without extensions then the easiest option is to make a CFA entry like this:
"Unknown FileType"*.>::load "<xyscripts>\UnknownFileTypesMenu.xys"

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

Re: Open with menu for unknown file-types

Post by RalphM »

As CFA's are checked from top to bottom why not place your catchall at the bottom of the list and let it deal with anything that didn't match anything above.
To run a script from CFA just use something like:

Code: Select all

"Unknown Filetype" *.*>::load YourScriptFile.xys;
Ralph :)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)

jupe
Posts: 2757
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Open with menu for unknown file-types

Post by jupe »

After reflection I thought of an easier way for you, just create 2 CFA
entries, the Unknown one at the bottom of the CFA list eg.
"Unknown FileType" *>::load "UnknownFileTypesMenu"

and the first item in CFA: {:Executable}>#

That should do what you require, and save a few lines of scripting.

Post Reply