[Script] WhiteSpaceCtxMenu
Posted: 21 Apr 2015 15:25
The purpose of this script is to call out specific menus when the user right clicks on the list panel white space. The menu which comes up is dependent on the file type of the current file. So you could set it up such that if you had a jpg or png file selected (i.e <curitem>), a menu with 4 or 5 different programs to select from would display, you'd choose one and the file would be opened in that program. So it similar to a right clicking on the file itself to bring up a context menu, but in this case the user is clicking the white space. I mentioned coming up with something similar to this here http://www.xyplorer.com/xyfc/viewtopic. ... 15#p122111 If no file is selected, the script brings up a default menu which can be anything the user wants (i.e, it could be as simple as bringing up the Favorite Files, Favorite Folders, call your own menu, or something more elaborate). Remember if a file is currently selected, but you'd rather just bring up the default menu rather than the specific file-type menu of a highlighted file, you can simply normal left click on white and then right click. You can also easily set the menu up such that some file types programs would immediately be run in a program of choice. For example, you could have it set such that if you have a single GIF file selected, it would bring up all the folder's GIFs in TheQwerty's 'HTMLImagePreview.xys' viewer. You could even set it up such that the script does something special if a folder is selected.
3 examples of the menus which surface if you right clicked with a certain file types selected along with an example default menu: No, it's nothing new as far as scripting goes, but setting up a script to run when you right click on white space is quite easy and can be very handy. So, why not improve it, make it a bit smarter by expanding its capabilities. I call the script "WhiteSpaceCtxMenu.xys". To use, the 2 lines in the XYplorer.ini file which have to change are:Obviously this is not the type of script a user can simply plop into his script folder and use. This is more of an idea and skeleton script you can use to arrive at your own. You have to take a few minutes an substitute your own programs to run based on the file types and any new files types as you wish. What I show here are just examples and certainly not my final script. I'm finding it easier than using the 'real' context menu or even PFAs since it it seems to be less clicking in many cases. If the file you'd like to run a program on is currently selected simply right click on white to bring up the the specific file type menu. If the file isn't currently selected you simply select with the left click and then move the mouse slightly and right click. If you'd rather bring up the default menu when there's a file currently hi-lighted, just left click on white (to un-select) and then follow with a right click.I hope you can get some use out of it or maybe some new, additional or better ideas will spawn from it. Once set-up, I'm finding easier to use than the normal context menu.
Thanks,
Ken Edit1: Modified the script to use SC gettokenindex rather than LikeI comparisons as per PeterH suggestion.
Edit2: Modified the "load" statement that uses the variable '$image' to show how to display 2 menus together (i.e., the Image menu and Copy move menu) as one menu with a separator between them
Edit3: Incorporated the use of new XY variable <selitem> and cleaned up the "if" , "elseif", and "else" structure. Also included obtaining "Favorite Folders" if you want to combine them with another menu. Otherwise you can leave that section out.
Edit4: Uploaded a zip version of script on 07/07/2015 in case there were issues due to copy and paste.
Edit5: Updated the run program with no menu examples to use "LikeI" in lieu of "==".
3 examples of the menus which surface if you right clicked with a certain file types selected along with an example default menu: No, it's nothing new as far as scripting goes, but setting up a script to run when you right click on white space is quite easy and can be very handy. So, why not improve it, make it a bit smarter by expanding its capabilities. I call the script "WhiteSpaceCtxMenu.xys". To use, the 2 lines in the XYplorer.ini file which have to change are:
Code: Select all
CEA_ListRightClickOnWhite=6
CEA_ListRightClickOnWhite_Script=load "<xyscripts>\WhiteSpaceCtxMenu.xys"
Code: Select all
/*** image file menu ***/
$image = <<<IMAGE
"Thumbnails in new Instance|:conf";
$jpgPath = getpathcomponent("<curitem>", "path");
run """<xy>"" /new ""$jpgPath"" /win=normal,10,10,1900,1050 /script=""::if(get('View') != '6') {#308};loadlayout('thumbs');open 'D:\Tools\AutoHotkey\AHK scripts\TB_XY_hide.ahk';"""; end(1); }
"ImageEye|D:\Graphics\Image Eye\Image Eye.exe";
Openwith "D:\Graphics\Image Eye\Image Eye.exe"; end(1);
"Irfanview|D:\Graphics\IrfanView\i_view32.exe";
openwith "D:\Graphics\IrfanView\i_view32.exe";end(1);
"Greenfish Icon Editor|D:\Graphics\Greenfish Icon Editor Pro\gfie64.exe" openwith "D:\Graphics\Greenfish Icon Editor Pro\gfie64.exe";
IMAGE;
/*** video file menu ***/
$vid = <<<VID
"BD Rebuilder|D:\DVD\BD Rebuilder\BDRB.exe" open "D:\DVD\BD Rebuilder\BDRB.exe";
"ConvertXtoDvd|D:\DVD\ConvertX\ConvertXtoDvd.exe" open "D:\DVD\ConvertX\ConvertXtoDvd.exe";
"EMDB|D:\DVD\EMDB\EMDB.exe" open "D:\DVD\EMDB\EMDB.exe";
"ImgBurn|D:\DVD\ImgBurn\ImgBurn.exe" open "D:\DVD\ImgBurn\ImgBurn.exe";
"MPC-HC|D:\DVD\MPC HomeCinema (x64)\mpc-hc64.exe" openwith "D:\DVD\MPC HomeCinema (x64)\mpc-hc64.exe";
"TMPGEnc|C:\Program Files (x86)\Pegasys Inc\TMPGEnc Authoring Works 4\TMPGEncAuthoringWorks4.exe" open "C:\Program Files (x86)\Pegasys Inc\TMPGEnc Authoring Works 4\TMPGEncAuthoringWorks4.exe";
"Video Joiner|D:\DVD\Boilsoft Video Joiner\EZMerge.exe" open "D:\DVD\Boilsoft Video Joiner\EZMerge.exe";
"VLC|D:\DVD\VLC\vlc.exe" openwith "D:\DVD\VLC\vlc.exe";
VID;
/*** text file menu ***/
$txt = <<<DOC
"NotePad++|D:\Tools\NotePad++\notepad++.exe" openwith "D:\Tools\NotePad++\notepad++.exe";
"PSPad|D:\Tools\PSPad\PSPad.exe" openwith "D:\Tools\PSPad\PSPad.exe";
"Notepad|C:\Windows\notepad.exe" openwith "C:\Windows\notepad.exe";
DOC;
/*** Folder menu ***/
$dir = <<<FOLDER
"Open Folder in new instance Thumbnail view|:viewthumbs"
run """<xy>"" /new ""$folder"" /win=normal,10,10,1900,1060 /script=""::if(get('View') != '6') {#308};loadlayout('thumbs');""", , 0, 0;
"Favorite Folders|:favs";
#550; end(1);
"Favorite Files|:favfiles";
#564; end(1);
FOLDER;
/*** Copy/Move menu ***/
$CopyMove = <<<COMO
"Copy|:copyto" #5;
"Move|:moveto" #4;
"Move to &Tools|:moveto";
moveto "H:\Misc\tools";
"-"
"Sort...|:sort" #320;
"Columns...|D:\Graphics\Icons\table-select-column-fatcow.ico" #360;
"View...|:viewthumbs" #301;
"-"
"New|:newfolder" #230;
COMO;
//***note: if you're not going to use Favorite Folders in conjunction with another menu you don't need this section
//***you can simply use #550
$FavFolderCount = getkey("Count", "Favorites");
if($FavFolderCount == "0") {$FFs = "No favorite folders";}
else {
$FFs = "";
$i = 1;
while ($i <= $FavFolderCount) {
$a = getkey("Fav$i", "Favorites");
$FFs = $FFs . $a . "<crlf>";
$i++;
}
}
$FavFolders = trim($FFs, "<crlf>", 'R');
if(exists("<selitem>") == 1) {
$selext = getpathcomponent("<selitem>", "ext");
if(gettokenindex($selext, "jpg|gif|png|ico", '|', 'i')) {load "$image;<crlf>-<crlf>$CopyMove", ,s; end(1);} //load image and CopyMove menus together
elseif(gettokenindex($selext, "avi|mp4|wmv|wma", '|', 'i')) {load "$vid", , s; end(1);} //load video menu
elseif(gettokenindex($selext, "ini|txt|nfo|inf|reg|ps1|vbs", '|', 'i')) {load "$txt", , s; end(1);} //load textfile menu
elseif("$selext" == "xys") {load("<selitem>"); end(1);} //no menu - example showing how you can automatically run an XY script on a right click on white
elseif("$selext" == "ahk") {openwith "D:\Tools\NotePad++\notepad++.exe"; end(1);} //no menu - example to open an AHK file for editing
else {load "$FavFolders;<crlf>-<crlf>$CopyMove", ,s; end(1);}
}
elseif(exists("<selitem>") == 2) {
perm $folder = "<curitem>";
load "$dir", , s; end(1);
}
else {
// when none of the other listed conditions or comparisons are met
load "$FavFolders;<crlf>-<crlf>$CopyMove", ,s; end(1) //this takes care of the "nothing selected" condition
//you can simply use #550 to load Favorite Folders (or Files #564) alone here or whatever script you
}
"_Terminate";
unset $folder; //you don't need this line or "_Terminate"; if you don't use variable $folder above
Thanks,
Ken Edit1: Modified the script to use SC gettokenindex rather than LikeI comparisons as per PeterH suggestion.
Edit2: Modified the "load" statement that uses the variable '$image' to show how to display 2 menus together (i.e., the Image menu and Copy move menu) as one menu with a separator between them
Edit3: Incorporated the use of new XY variable <selitem> and cleaned up the "if" , "elseif", and "else" structure. Also included obtaining "Favorite Folders" if you want to combine them with another menu. Otherwise you can leave that section out.
Edit4: Uploaded a zip version of script on 07/07/2015 in case there were issues due to copy and paste.
Edit5: Updated the run program with no menu examples to use "LikeI" in lieu of "==".