Get two selected items

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
klininger
Posts: 2
Joined: 22 Mar 2016 17:04

Get two selected items

Post by klininger »

I am trying to build a toolbar button to launch a text comparer. I works by comparing two files. I see <curitem> but I need access to both items. I would love to use <items>, but it's only available for "Open with" for some reason.

Can anyone help me out?

Thanks in advance!

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Get two selected items

Post by bdeshi »

Welcome to the club! :maf:

You can use get('SelectedItemsPathNames', '|') or the <selitems> variable as <selitems '|'> both of which return a pipe-separated list of all selected items.


btw, I use this oddly indented script for launching BeyondCompare with currently selection in one or both panes (or current pane paths (or dropped items)).

Code: Select all

INCLUDE "inc\in.xyi"; //get the in() UDF from Script Exchange > User Functions Exchange
"BeyondCompare"
  //prio: drop > 2xSelxPane > 1xSelxPanes

  $app = """<xypath>\..\BeyondCompare\BCompare.exe""";
  $files = '""'; $cmd=''; $mode ='';
  $dr    = replace(<drop>, <crlf>, '|');
  $fa    = get('SelectedItemsPathNames', '|', 'a');
  $fi    = get('SelectedItemsPathNames', '|', 'i');
  if     (gettoken($dr, 'count', '|') == 2)  { $files = $dr; }
  elseif (gettoken($fa, 'count', '|') == 2)  { $files = $fa; }
  elseif (gettoken($fa, 'count', '|') == 1)&&
         (gettoken($fi, 'count', '|') == 1)  { $files = $fa.'|'.$fi; }
  else   {
           $da = get('path','a');
           $di = get('path','i');
           if   (strpos($da,'paper:') != 1)||
                (strpos($di,'paper:') != 1)  {
                $files = $da.'|'.$di;
                $mode  = "Folder";
            }
         }

  if ($mode == '') {
    $type1 = filetype(gettoken($files, 1, '|'));
    $type2 = filetype(gettoken($files, 2, '|'));
    $type  = $type1.'|'.$type2;
    if in($type,'Binary|Empty|Cannot|Nofile') { $mode = 'Hex'; }
    else {$mode = 'Text';}
  }
  $files = '"'.replace($files,'|','" "').'"';
  $cmd = "/fv=""$mode Compare""";
  run "$app $files $cmd";
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

klininger
Posts: 2
Joined: 22 Mar 2016 17:04

Re: Get two selected items

Post by klininger »

Beauty. Thanks!

Post Reply