Open Focused Item with PFA

Discuss and share scripts and script files...
Post Reply
n2k
Posts: 17
Joined: 20 Mar 2014 10:39

Open Focused Item with PFA

Post by n2k »

Originated from this post: http://www.xyplorer.com/xyfc/viewtopic.php?f=3&t=11373
Again thanks to TheQwerty for giving me a head start with this :)

The script below is what I came up with and fully satisfies my needs as that it doesn't override the default behavior of Enter / Double-Click
This can be bound to a shortcut and is intended to expand on the Open Focused Item shortcut Ctrl+Enter

It has the following features:
  • reads PFA list from ini file
    • so remember to save settings after making changes to your PFA list
  • designed to support the following syntax: |"caption|path/to/icon" ext1;ext2>path/to/program
    • for this script to use a PFA it is required to begin each PFA entry with a | (pipe) and it should be enabled (ticked) in the list.
    • The caption is optional, the path/to/icon is optional, the path/to/executable doesn't need to be quoted
How to use this script:
  1. Press SELECT ALL on the code block below
  2. Press Ctrl+C to copy it to clipboard
  3. In XYplorer go to User -> Manage Commands...
  4. Select the the Run Script Category on the left side
  5. Click the New button on the right side
  6. Enter Open Focused Item with PFA as Caption
  7. Click the Edit button right next to the Script: field
  8. Press Ctrl+V in the Edit Script window
  9. Click the OK button
  10. Click the Assign Keyboard Shortcut... button
  11. Press Ctrl+Enter (or whatever shortcut you want)
  12. Click the OK button of the Free Keyboard Shortcuts window
  13. Click the OK button of the Manage User-Defined Commands window
  14. Done

Code: Select all

"Open Focused Item with PFA"
  // designed to support the basic ext format from PFAs: ext;ext>path/to/executable
  // could possibly support more, or might break, if you could test it and report back that'd be great :)
  
  $PFACount = getkey("Count", "FileAssoc");
  // might improve performance when just reading file once instead of doing it for every single PFA
  $PFAMatch = "";
  while ($PFACount > 0) {
    $PFA = getkey($PFACount, "FileAssoc");
    // if the PFA is activated (has +) and not already overriding the default application (has |)
    // the compare function returns 0 if the strings are equal
    if (!compare(substr($PFA, 0, 2), "+|")) {
      if(gettokenindex('"', gettoken($PFA, 1, ">", "t"), ">")) {
        $PFAnoCaption = gettoken($PFA, 3, '"', t, 2);
      }
      else {
        $PFAnoCaption = substr(gettoken($PFA, 1, ">", t, 2), 2);
      }
      // If the focused item's extension is in the list
      $PFAexts = gettoken($PFAnoCaption, 1, ">", "t");
      if (gettokenindex(<curext>, $PFAexts, ";")) {
        $PFAMatch = $PFA;
        break;
      }
    }
    $PFACount--;
  }
  
  if ($PFAMatch) {
    openwith gettoken($PFAnoCaption, 2, ">", "t"), "s", <curitem>;
  }
  else {
    #162; // File | Open Focused Item
  }

Post Reply