[Script] WhiteSpaceCtxMenu

Discuss and share scripts and script files...
klownboy
Posts: 4402
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: [Script] WhiteSpaceCtxMenu

Post by klownboy »

CookieMonster wrote:What do you mean by alignment issues ?
I simply meant if the lines of code are fully over to the left side where they need to be and in other cases have a few spaces in front of the code lines (i.e., make sure you haven't made any changes of that nature to the code in the first post).

CookieMonster

Re: [Script] WhiteSpaceCtxMenu

Post by CookieMonster »

I can verify that I haven't made any alignment issues; no one else has problem with running the script but me, arghhh ! :evil: :evil: :evil: :evil:

Stef123

Re: [Script] WhiteSpaceCtxMenu

Post by Stef123 »

CookieMonster wrote:no one else has problem with running the script but me, arghhh ! :evil: :evil: :evil: :evil:
To ease your mind, let me tell you that I struggled enormously with several syntax issues, notably Heredoc naming and alignment, but also things like quotes-handling and bracketing. Hardly ever do I get my scripts working on the first go-around. I've spent considerable time re-reading scripting help

@Ken
Yes, a a ready-made .xys file helps non-programmers like me to take some of the frustration out of scripting. Makes it easier to tweak and adjust when you can be sure you already have a working syntax in place.

CookieMonster

Re: [Script] WhiteSpaceCtxMenu

Post by CookieMonster »

Stef - From what I can see, there are no syntax issues; although I understand syntax issues, learning different programming languages I do make quite a few of those mistakes. :(

Why is this not working, if there are no syntax issues, it's really frustrating; must I create a video to demonstrate what I'm doing ? :? :(

klownboy
Posts: 4402
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: [Script] WhiteSpaceCtxMenu

Post by klownboy »

Hi CookieMonster, I uploaded a zip version of the script on the first post. Try that to eliminate possible syntax or copy/paste issues before we try anything else.

CookieMonster

Re: [Script] WhiteSpaceCtxMenu

Post by CookieMonster »

klownboy wrote:Hi CookieMonster, I uploaded a zip version of the script on the first post. Try that to eliminate possible syntax or copy/paste issues before we try anything else.
I replaced my WhiteSpaceCtxMenu.xys with the one you uploaded and it worked :)

When I remove everything from the script that you uploaded and leave only what you see below, as I had previously, it doesn't work ?
/*** 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;

Stef123

Re: [Script] WhiteSpaceCtxMenu

Post by Stef123 »

CookieMonster wrote:[When I remove everything from the script that you uploaded and leave only what you see below, as I had previously, it doesn't work ?
/*** 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;
Well, that may explain it, imo - but you better wait for Ken or someone else with more expertise to confirm it.
You define the variable "$txt" - but then you do nothing with it, it simply sits there and waits and waits and waits.....

What's missing in your script - if you really left out EVERYTHING else - is the decision-making part, the section that decides what's gonna happen based on the current selection (if any) and its extension.

So what you really need to include - and adjust - is the bottom part of the script, starting with

Code: Select all

     if (exists("<selitem>") == 1) {
      $selext = getpathcomponent("<selitem>", "ext");
     .......

klownboy
Posts: 4402
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: [Script] WhiteSpaceCtxMenu

Post by klownboy »

Hey CookieMonster, glad to hear it finally worked for you. Using that portion you showed by itself will not work. That's only the heredoc section for a menu that displays if you have a text file selected. But, it also needs the section which actually runs, or I should say loads the heredoc created variable menus based on file type (extension). You have to include the section starting with if(exists("<selitem>") == 1) { all the way down to but not including: "_FavFolders : _FavFolders";

I would suggest that you simply modify each section for the different file types to specify your own programs. That's what make the script powerful...having it set to bring up a different menu that you've personally created for each file type.

Thanks Stef123, you're absolutely correct. I had this mostly written when I saw your post. If it was a little later I wouldn't have bothered.

CookieMonster

Re: [Script] WhiteSpaceCtxMenu

Post by CookieMonster »

Code: Select all

/*** text file menu ***/
if(exists("<selitem>") == 1) {
        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);}
     }
   $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;
I included the condition, and the menu works, except, in the menu I get;

$FavFolders;
$CopyMove


What is wrong with the code; so I can customize the menu for various file types ? :)

klownboy
Posts: 4402
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: [Script] WhiteSpaceCtxMenu

Post by klownboy »

CookieMonster wrote:What is wrong with the code; so I can customize the menu for various file types ?
There's nothing wrong with the original. You can use its structure as is to have it work for various file types you just have to change the programs referred to in the various menus. You bastardized it, which is fine, but you did it incorrectly. You can't get rid of the lead "if" statement and start off with "elseif". As I said, you should be modifying the original with your own programs. You can even get rid of file types, but you have to keep that load section in tact unless you really know what you're doing. You also deleted the variable $selext line. You get $FavFolders and $CopyMove because you deleted those sections of the script. Try this below. If a text file is not selected it will bring up Favorite Folders. If a "ahk" file is selected it will open it immediately in notepad. If a "xys" file is selected it will load it.

Code: Select all

/*** 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;

   if(exists("<selitem>") == 1) {
	$selext = getpathcomponent("<selitem>", "ext");
        if(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 "C:\Windows\notepad.exe"; end(1);}   //no menu - example to open an AHK file for editing
        else {#550; end(1);}
   }
	else {
	     #550
		  }

CookieMonster

Re: [Script] WhiteSpaceCtxMenu

Post by CookieMonster »

Ahh, the condition loads the variables, silly me, why I butchered the script as I did was a dumb mistake on my part. :(

Klownboy - The script you recently posted in your most recent message works. I have a question, how did you get the custom menu for XYS files when it's not calling a variable ? :D

Code: Select all

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

klownboy
Posts: 4402
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: [Script] WhiteSpaceCtxMenu

Post by klownboy »

CookieMonster wrote:The script you recently posted in your most recent message works. I have a question, how did you get the custom menu for XYS files when it's not calling a variable ?
It's not written to provide a custom menu for that situation. That was an example of how to load the script immediately with no menu (i.e., select the script, the file with an "xys" extension, and right click on white and it should run (no menu)). You could have a menu come up if you wanted, but probably the only choices you would have are: Load the script & Edit the script. Though you could have: Load the script (with stepping) & Load script (no stepping) & Edit script. So you'd make a variable using heredoc as we did for text files "$txt". Try it if you like and see if can make it work. Remember, besides writing the new section for an "xys" files (call it variable $xys), you need to add a line which loads $xys after the line which loads $txt. Show us what you come up with. If it doesn't work I'll help you out. Good luck.

CookieMonster

Re: [Script] WhiteSpaceCtxMenu

Post by CookieMonster »

This is what I came up with for PSD files before I begin adding more different types.

Code: Select all

/*** 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;

  $PSD = <<<PSD 
"Photoshop|"C:\Program Files\Adobe\Adobe Photoshop CC 2015\Photoshop.exe""
PSD;

   if(exists("<selitem>") == 1) {
   $selext = getpathcomponent("<selitem>", "ext");
        if(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 "C:\Windows\notepad.exe"; end(1);}   //no menu - example to open an AHK file for editing
        elseif("$select == "psd") 
        else {#550; end(1);}
   }
   else {
        #550
        }

klownboy
Posts: 4402
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: [Script] WhiteSpaceCtxMenu

Post by klownboy »

Hi CookieMonster, the only problem is, you only have one menu item. Not much sense in having a menu with one item. :) Don't you have other graphics program as well like viewers (e.g., Irfanview, ImageEye, etc) that you could add to your menu. Or, why not have a more general image menu similar to one I have in the original version. All you would have to do is add the "psd" extension to the list of extensions in the $image variable section. You'd get rid of references to programs you don't have installed and add one for Photoshop. So if the file selected is a psd you would choose Photoshop from the menu. For your case above though, you need to add the open or openwith statement after the elseif...

Code: Select all

elseif("$select" == "psd") {openwith "C:\Program Files\Adobe\Adobe Photoshop CC 2015\Photoshop.exe"; end(1);}   
Another option would be to handle it like I did for "xys" script files or "ahk" files - automatically run the file with Photoshop when you right click on white if the extension is "psd" with no menu. As you can see there are many ways to handle individual cases which is what makes it powerful. It just a matter of setting it up the way you want it to work.

CookieMonster

Re: [Script] WhiteSpaceCtxMenu

Post by CookieMonster »

You'd get rid of references to programs you don't have installed and add one for Photoshop.
Sorry, I don't understand :)

The name of the variable matters, in this case, if it's PSD it will, (maybe I'll answer my own question, with this question) only run the menu if a PSD file is selected ?
$txt = <<<DOC

Code: Select all

"Photoshop|"C:\Program Files\Adobe\Adobe Photoshop CC 2015\Photoshop.exe"
I'm getting a dubious error on this line, which I assume is the spacing in the folder name where Photoshop exists ?

Post Reply