Possible to open file with other program filtered by PFA?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
n2k
Posts: 17
Joined: 20 Mar 2014 10:39

Possible to open file with other program filtered by PFA?

Post by n2k »

Hey!

I'm fairly new to all this, but this is what I would like to achieve:
I want to open a selected MKV file using the default program associated with it (via Windows) by using Enter or Double Click but I want to open the same MKV file using a PFA filtered by the file extension by using Ctrl+Enter. The application that will be used for the selected MKV item is defined by using PFA's (Portable File Associations):

Code: Select all

|"&\PotPlayer" mp4;mkv;avi>C:\Program Files\DAUM\PotPlayer\PotPlayerMini64.exe
But I'm running into some walls, probably because I'm approaching this the wrong way :p
  1. I can't use PFA without using the pipe | because then it will override the Enter & Double Click when opening the file
  2. I can't use a reversed scenario, setting the PFA to be the default and rebind the keys, since Enter & Double Click cannot be rebound using CKS (Customize Keyboard Shortcuts) panel.
  3. So by using the pipe | I'm forced to use PFA's via a popup menu, which means: I have to use one additional step to achieve what I want, by using a & accelerator in the PFA, I've set it up so that when I press backslash \ it will use PotPlayer, but still isn't really convenient.
There probably is a way to solve this using scripting, but I couldn't find a scripting command to auto-select something from a popup menu, or a command that can directly retrieve my PFA's.

Any thoughts on this?

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Possible to open file with other program filtered by PFA

Post by TheQwerty »

Unfortunately, I don't think you can accomplish this with PFA.

What you could do is...
  1. Remove the Ctrl+Enter shortcut from File > Open Focused Item.
  2. Create a new Run Script or Load Script File user command.
  3. Set the script for the new command to the script found below - make sure you modify the examples to suit your needs.
  4. Assign this user command the shortcut Ctrl+Enter
Now Ctrl+Enter will attempt to open the focused item using the executable defined in the script, or fall back to XY's normal handling if the extension is not defined in the script.

It would take some effort if you want the script to use the fully supported syntax of PFA but it should be possible with some work.

HTH

Code: Select all

"Open Focused Item (with fake PFA)"
 // Set the following lines to the alternate programs you want to use...
 // This supports the very basic ext;ext>executable format from PFAs only.
 $PFAs = <<<#PFA
mp4;mkv;avi>C:\Program Files\DAUM\PotPlayer\PotPlayerMini64.exe
txt;ini;nfo>C:\Program Files\Sublime\sublime_text.exe
#PFA;


 // Cleans up PFA list.
 $PFAs = FormatList($PFAs, 'ted', "<crlf>");

 $f = "<focitem>";

 $ext = GetPathComponent($f, 'ext');
 foreach ($pfa, $PFAs, "<crlf>") {
   if ($pfa != '') {
     // If the focused item's extension is in the list...
     $exts = GetToken($pfa, 1, '>', 't', 1);
     if (GetTokenIndex($ext, $exts, ';', 'i')) {
       // Open the focused item with the specified executable and end the script.
       $exe = GetToken($pfa, 2, '>', 't', 2);
       OpenWith $exe, 's', $f;
       End true;
     }
   }
 }

 // If no match is found use the original command and let XY figure it out.
 #162; // File | Open Focused Item

n2k
Posts: 17
Joined: 20 Mar 2014 10:39

Re: Possible to open file with other program filtered by PFA

Post by n2k »

Hey TheQwerty thanks for your script, it really helped me getting a head start into scripting :)

see this post for my script: http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=11469

Post Reply