External App with items from both panes BeyondCompare WinMer

Discuss and share scripts and script files...
Post Reply
Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

External App with items from both panes BeyondCompare WinMer

Post by Stefan »

For some external applications like comparing tools you need to launch this app with path or file name from both panes.

Right now (v8.70.0151 - 2009-12-16) you have to do an little trick (FYI: >Here< it is discussed to implement tokens for this issue.)
to provide items from both panes to this app:

* First get the name of the path/item of the first pane,
* then switch the focus to the other pane,
* now get the name of the path/item from this other pane.
* Maybe, if you want, switch focus back to first pane again.

Example script:
$FileOne = <curitem>;
Focus "PI"; //switch focus to other pane
$FileTwo = <curitem>;
Focus "PI"; //switch focus back (if needed)


>Here< is an list of all Script_Variables.


********************************************************************
EDIT: there are now new vars for that issue wrote:v8.70.0152 - 2009-12-17 15:28
+ New variable <get path [pane]> returns the unslashed path of any of the two panes.
For example: <get path> //active pane's path || <get path i> //inactive pane's path
Example script:
$FileOne = <get path>; //active pane's path
$FileTwo = <get path i>; //inactive pane's path

********************************************************************



Here i have done an try to integrate "Beyond Compare" (or WinMerge) as comparing tool into my XYplorer setup:
1.) save the "BCompare.xys" from below into an plain text file named "BCompare.xys" in your XYplorer\Scripts -folder
2.) to launch that script you have several possibilities, e.g. adding an new toolbar button:
If you want, add an CTB button to call the script:
If you want, add an CTB button to call the script:
CTB_BCompare.PNG (18.35 KiB) Viewed 3648 times
3.) If you launch the script you will see an new dialog popping up:
When the script is launched you will see this dialog:
When the script is launched you will see this dialog:
Script_BCompare_001.PNG (12.18 KiB) Viewed 3687 times
Just click at an item to launch BeyondCompare with the selected files/folders as parameter.
(Note: just modify the "_Execute" section to launch an other application like WinMerge)

BCompare.xys

Code: Select all

/*
Execute Beyond Compare
BCompare_20091210.xys

LICENSE:
    This script is free software: you can redistribute and/or modify it.
    This script is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
    If your computer implode or your files gets lose, don't blame me, so
    please try this script first with some test files in an virtual machine.
     
Purpose:     
		Script to launch external tool with selected files/folders as parameter

How to use:
	1.) Copy the script below in an file "..\scripts\BCompare.xys".
	2.) Then, e.g., add an CTB toolbar button:
		Name: BCompare
		Icon: path\to\Beyond Compare 3\BCompare.exe
		On Click: load BCompare;
	3.) Select two files or folders in XY.
	4.) execute this script.
	5.) you are prompted with an menu
*/

// the script:

"Run BCompare with..."
   
"... Current open Folders from L/R pane"
     Global $ArgOne, $ArgTwo;
     $ArgOne = <curpath>;
     Focus "PI";
     $ArgTwo = <curpath>;
     Focus "PI";
     Sub "_Execute";
    
"... Selected Files or Folders from L/R pane"
     Global $ArgOne, $ArgTwo;
     End ("<curitem>"==""),  "No file selected!"; //check if any file is selected
     $ArgOne = <curitem>;
     Focus "PI";
     End ("<curitem>"==""),  "No file selected!"; //check if any file is selected
     $ArgTwo = <curitem>;
     Focus "PI";
     Sub "_Execute";
 
"... Selected Files or Folders from same pane"
     Global $ArgOne, $ArgTwo;
     $SelectedFiles = getinfo("SelectedItemsPathNames","|");
     $ArgOne = gettoken($SelectedFiles, 1, "|");
     $ArgTwo = gettoken($SelectedFiles, 2, "|");
     Sub "_Execute";
  

"_Execute"
     Global $ArgOne, $ArgTwo;
     end (exists("<xypath>\..\Beyond Compare 3\BCompare.exe")=="0"), "BCompare.exe not found.<crlf>Edit script and check path."; 
     run "<xypath>\..\Beyond Compare 3\BCompare.exe" "$ArgOne" "$ArgTwo"; 
     //run "<xypath>\..\WinMerge\App\WinMerge\WinMergeU.exe" "$ArgOne" "$ArgTwo"; 
-
"Cancel"
-
"Edit this &script : edit"
   self $ScriptFile, file;
   OpenWith "<xypath>\Tools\NotePad2\Notepad2.exe", ,$ScriptFile;
HTH? :wink:

BTW, i have seen >here< an similar script.

Edit: added some more comments.
Last edited by Stefan on 21 Jan 2010 09:52, edited 5 times in total.

stanmarsh
Posts: 85
Joined: 10 Mar 2009 07:43

Re: External App with items from both panes BeyondCompare WinMer

Post by stanmarsh »

i tested this out in winmerge and it works! no more drag+drop of files to winmerge, thank you Stefan!

Jim Yuill
Posts: 2
Joined: 28 Jan 2022 04:54

Re: External App with items from both panes BeyondCompare WinMer

Post by Jim Yuill »

13 years later, the posted script is great--thanks.

I updated the script, and added another way of specifying the files to be compared:
    For left file to be compared: copy file-path to clipboard
    (XYplorer shortcut to copy file-path to clipboard: select file, ctrl+p)
      Select right file to be compared

      Code: Select all

      /*
      Execute Beyond Compare
      BCompare_20220127.xys
      
      LICENSE:
          This script is free software: you can redistribute and/or modify it.
          This script is distributed in the hope that it will be useful,
          but WITHOUT ANY WARRANTY; without even the implied warranty of
          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
          If your computer implode or your files gets lose, don't blame me, so
          please try this script first with some test files in an virtual machine.
           
      Purpose:     
      		Script to launch external tool with selected files/folders as parameter
      
      How to use:
      	1.) Copy the script below in an file "..\scripts\BCompare.xys".
      	2.) Then, e.g., add an CTB toolbar button:
      		Name: BCompare
      		Icon: path\to\Beyond Compare 3\BCompare.exe
      		On Click: load BCompare;
      	3.) Select two files or folders in XY.
      	4.) execute this script.
      	5.) you are prompted with an menu
      */
      
      // the script:
      
      "Run BCompare with..."
         
      "... Current open Folders from L/R pane"
           Global $ArgOne, $ArgTwo;
           $ArgOne = <curpath>;
           Focus "PI";
           $ArgTwo = <curpath>;
           Focus "PI";
           Sub "_Execute";
          
      "... Selected Files or Folders from L/R pane"
           Global $ArgOne, $ArgTwo;
           End ("<curitem>"==""),  "No file selected!"; //check if any file is selected
           $ArgOne = <curitem>;
           Focus "PI";
           End ("<curitem>"==""),  "No file selected!"; //check if any file is selected
           $ArgTwo = <curitem>;
           Focus "PI";
           Sub "_Execute";
       
      "... Selected Files or Folders from same pane"
           Global $ArgOne, $ArgTwo;
           $SelectedFiles = getinfo("SelectedItemsPathNames","|");
           $ArgOne = gettoken($SelectedFiles, 1, "|");
           $ArgTwo = gettoken($SelectedFiles, 2, "|");
           Sub "_Execute";
      
      /*
      How to specify files to be compared:
      * For left-file to be compared: copy file-path to clipboard
      (XYplorer shortcut to copy file-path to clipboard: select file, ctrl+p)
      * In active pane, select right-file to be compared
      */
      "... File-path in clipboard, and selected file in active pane"
           Global $ArgOne, $ArgTwo;
           $SelectedFiles = getinfo("SelectedItemsPathNames","|");
           $ArgOne = <clp>;
           $ArgTwo = gettoken($SelectedFiles, 1, "|");
           Sub "_Execute";
         
      "_Execute"
           Global $ArgOne, $ArgTwo;
           end (exists("C:\Program Files\Beyond Compare 4\BCompare.exe")=="0"), "BCompare.exe not found.<crlf>Edit script and check path."; 
           run "C:\Program Files\Beyond Compare 4\BCompare.exe" "$ArgOne" "$ArgTwo"; 
           //run "<xypath>\..\WinMerge\App\WinMerge\WinMergeU.exe" "$ArgOne" "$ArgTwo"; 
      -
      "Cancel"
      -
      "Edit this &script : edit"
         self $ScriptFile, file;
         OpenWith "<xypath>\Tools\NotePad2\Notepad2.exe", ,$ScriptFile;
      

      Jim Yuill
      Posts: 2
      Joined: 28 Jan 2022 04:54

      Re: External App with items from both panes BeyondCompare WinMer

      Post by Jim Yuill »

      There's a bug in the original script. The call to the editor doesn't work.

      I fixed the bug in my version of the script. The fixed script is posted below, and on my GitHub repo:
      https://github.com/jimyuill/Workstation ... or-Windows

      Code: Select all

      /*
      Execute Beyond Compare (version 1/28/2022)
      (Original version 12/2009, by Stefan.)
      
      DESCRIPTION:
      * This script runs in XYplorer (an awesome file explorer).
      * In XYplorer, the user selects two files, and they are opened in the specified
        program, e.g., Beyond Compare (an awesome file-compare tool).
        (The program to use is hard-coded in the script.)
      
      EXAMPLE:
      * With Windows File-Explorer, Beyond Compare (BC) can be called by right-clicking 
        on the two files to be compared, and they automatically get opened in BC, 
        e.g., "Select left file to compare".
        However, that feature does not appear to be available with XYplorer.
      * This script implements a similar feature in XYplorer: 
        the files to be compared are selected, then opened in Beyond Compare.
      * The script can be edited so any program is called, instead of Beyond Compare.
      
      INSTALLATION and USE:
      
      How to use:
      	1.) Copy the script below in an file "..\scripts\BCompare.xys".
      	2.) Then, e.g., add an CTB toolbar button:
      		Name: BCompare
      		Icon: path\to\Beyond Compare 3\BCompare.exe
      		On Click: load BCompare;
      	3.) Select two files or folders in XY.
      	4.) execute this script.
      	5.) you are prompted with an menu
          
      Additional documentation is in the original post for the script:
      https://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=4420
      
      
      HISTORY:
      * 12/2009: This script was originally written by Stefan, and posted here:
        https://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=4420
      * 1/2022: The script was enhanced by Jim Yuill, to get one of the file-paths
        from the clipboard.  Also, a bug was fixed in the call to the editor.
        The code was put on GitHub:  https://github.com/jimyuill/Workstation-tools-for-Windows
      
      LICENSE (retained from original script):
          This script is free software: you can redistribute and/or modify it.
          This script is distributed in the hope that it will be useful,
          but WITHOUT ANY WARRANTY; without even the implied warranty of
          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
          If your computer implode or your files gets lose, don't blame me, so
          please try this script first with some test files in an virtual machine.
          
      */
      
      // the script:
      
      "Run BCompare with..."
         
      "... Current open Folders from L/R pane"
           Global $ArgOne, $ArgTwo;
           $ArgOne = <curpath>;
           Focus "PI";
           $ArgTwo = <curpath>;
           Focus "PI";
           Sub "_Execute";
          
      "... Selected Files or Folders from L/R pane"
           Global $ArgOne, $ArgTwo;
           End ("<curitem>"==""),  "No file selected!"; //check if any file is selected
           $ArgOne = <curitem>;
           Focus "PI";
           End ("<curitem>"==""),  "No file selected!"; //check if any file is selected
           $ArgTwo = <curitem>;
           Focus "PI";
           Sub "_Execute";
       
      "... Selected Files or Folders from same pane"
           Global $ArgOne, $ArgTwo;
           $SelectedFiles = getinfo("SelectedItemsPathNames","|");
           $ArgOne = gettoken($SelectedFiles, 1, "|");
           $ArgTwo = gettoken($SelectedFiles, 2, "|");
           Sub "_Execute";
      
      /*
      How to specify files to be compared:
      * For left-file to be compared: copy file-path to clipboard
      (XYplorer shortcut to copy file-path to clipboard: select file, ctrl+p)
      * In active pane, select right-file to be compared
      */
      "... File-path in clipboard, and selected file in active pane"
           Global $ArgOne, $ArgTwo;
           $SelectedFiles = getinfo("SelectedItemsPathNames","|");
           $ArgOne = <clp>;
           $ArgTwo = gettoken($SelectedFiles, 1, "|");
           Sub "_Execute";
         
      "_Execute"
           Global $ArgOne, $ArgTwo;
           end (exists("C:\Program Files\Beyond Compare 4\BCompare.exe")=="0"), "BCompare.exe not found.<crlf>Edit script and check path."; 
           run "C:\Program Files\Beyond Compare 4\BCompare.exe" "$ArgOne" "$ArgTwo"; 
           //run "<xypath>\..\WinMerge\App\WinMerge\WinMergeU.exe" "$ArgOne" "$ArgTwo"; 
      -
      "Cancel"
      -
      "Edit this &script : edit"
         //self $ScriptFile, file;
         $ScriptFile= self ("file");
         OpenWith "C:\Program Files\Notepad++\notepad++.exe", ,$ScriptFile;
      

      admin
      Site Admin
      Posts: 60357
      Joined: 22 May 2004 16:48
      Location: Win8.1 @100%, Win10 @100%
      Contact:

      Re: External App with items from both panes BeyondCompare WinMer

      Post by admin »

      13 years later, risen from the grave. Cool. :tup:

      eil
      Posts: 1617
      Joined: 13 Jan 2011 19:44

      Re: External App with items from both panes BeyondCompare WinMer

      Post by eil »

      i'm not sure if the script i'm using for BeyondCompare is mine or an adaptation of smb else, so i'll just mention a pattern, so maybe it will be useful for others. Main difference is that selecting first item for left panel is stored in perma-variable, the whole script used trough catalog item with consecutive clicks, and little comparison is added = script checks if both selected were folders or text files, to properly send comparу parameters(i was lazy to make same for image/sound check).
      Win 7 SP1 x64 100% 1366x768

      Post Reply