[Script] WhiteSpaceCtxMenu

Discuss and share scripts and script files...
Post Reply
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 »

The name of the variable doesn't matter as long as you use the same name in the heredoc statement and in the load statement. What matters is the extension or list of extensions. I didn't notice last night but you have an extra " in the line after the |. So it should be:

Code: Select all

"Photoshop|C:\Program Files\Adobe\Adobe Photoshop CC 2015\Photoshop.exe" openwith """C:\Program Files\Adobe\Adobe Photoshop CC 2015\Photoshop.exe""";
My point was if you are only going to have one choice when the selected file is a "psd" file why would you want a menu to come up at all - just to select only one choice? When there is only one choice in a menu, XY will immediately run the program anyway (i.e., the menu will not display). You might as well write the "psd" selection as I did with "xys" with no heredoc statement or variable.

Code: Select all

elseif("$selext" == "psd") {openwith "C:\Program Files\Adobe\Adobe Photoshop CC 2015\Photoshop.exe"; end(1);}
Because of spaces you may need to triple quote the photoshop path/name.
Edit: Didn't notice initially, but also you didn't have the action statement after the menu item for Photoshop. Please look at the other examples.

CookieMonster

Re: [Script] WhiteSpaceCtxMenu

Post by CookieMonster »

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") {openwith """C:\Program Files\Adobe\Adobe Photoshop CC 2015\Photoshop.exe"""; end(1);}
        else {#550; end(1);}
   }
   else {
        #550
        }
I continue to get errors and I triple quoted file paths with contain spaces. I don't know what you meant that I'm missing an action statement ? I will be adding more menu items, for now it will be a lonely one menu item :)

highend
Posts: 14597
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: [Script] WhiteSpaceCtxMenu

Post by highend »

No need to triple quote entries in the heredoc syntax...
Missing quote (in fact it's superfluous but however...) in the elseif statement...
Wrong variable name in the elseif statement...
One of my scripts helped you out? Please donate via Paypal

CookieMonster

Re: [Script] WhiteSpaceCtxMenu

Post by CookieMonster »

Missing quote (in fact it's superfluous but however...) in the elseif statement...
Wrong variable name in the elseif statement...

Code: Select all

 elseif("$select == "PSD") {openwith """C:\Program Files\Adobe\Adobe Photoshop CC 2015\Photoshop.exe"""; end(1);}
?

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 »

Thanks highend, I forgot there's no need in the heredoc...I got carried away and I'm going insane. :)

CookieMonster, careful of your spelling look at variable $select. It should be $selext. As highend stated since you have a path/ name that has spaces you'll need triple quotes the open/run/openwith statements but not in the heredoc. I don't believe the capitalization of "PSD" makes a difference in the case but why do it? We didn't do it elsewhere and it wasn't in your previous post.

CookieMonster

Re: [Script] WhiteSpaceCtxMenu

Post by CookieMonster »

The heredoc has single quotes the openwith as stated has triple quotes, due to the spaces in the file name, I continue to get an error on this line ?

Code: Select all

"Photoshop|C:\Program Files\Adobe\Adobe Photoshop CC 2015\Photoshop.exe"

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: [Script] WhiteSpaceCtxMenu

Post by SkyFrontier »

Any way I could invoke the right click on white using the keyboard?
The keyboard "menu" key triggers the default right click, not WhiteSpaceCtxMenu's one.

(using the dumb hat)
-load "WhiteSpaceCtxMenu"; assigned to a CKS (UDC).

Thanks for sharing, nice little thing!
Last edited by SkyFrontier on 09 Jul 2015 20:55, edited 1 time in total.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

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 heredoc has single quotes the openwith as stated has triple quotes, due to the spaces in the file name, I continue to get an error on this line ?
That's because the line's not doing anything. You're specifying a menu item name and the icon to use but you have specify the action you want to take place when you click on the menu item. Please look at my post above http://www.xyplorer.com/xyfc/viewtopic. ... 60#p125998 - at the first code line. I told you that you were missing the command to open the file. Again, please look at the other examples when you add to or modify the code. You can copy that, but as explained since then, you only need single quotes not triple and don't forget the semi-colon at the end.
Last edited by klownboy on 09 Jul 2015 20:49, edited 1 time in total.

highend
Posts: 14597
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: [Script] WhiteSpaceCtxMenu

Post by highend »

I continue to think that posting anything is ... pointless...

@Ken
- I'd use LikeI for extension comparison
- Triple quotes for openwith aren't necessary if it's only a call without any parameters or variables that need to be resolved
so "C:\Program Files\Adobe\Adobe Photoshop CC 2015\Photoshop.exe" is absolutely enough
- Btw I recommend to use camel case variables or separate parts via an underscore. Combined variable names all in lowercase are "hard" to read. At least imho :) You don't need to put most variables in quotes (unless you plan to do some string manipulation with them or they are part of a path).

E.g. $selExt LikeI "xys" is sufficient and it works with strings that contain spaces as well like (for address bar):

::$a="hello world"; if($a LikeI "Hello World") { msg true; }
One of my scripts helped you out? Please donate via Paypal

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 »

Thanks highend. I don't know why I didn't in this case, but I do usually combine some upper with the lower case. It does make it much easier to zero in on the name or meaning of the name/variable. The use of the underscore helps as well like, $p_XXX for perms or $g_XXX for globals. I should start doing that.

Concerning the "LikeI", going back to the beginning of the thread, see 1st post, Edit1. Soon after posting PeterH recommended the gettokenindex which I though would be fine as long as you are using case insensitive flag "i". In this particular case though, as far as the comparison of $selext to many extensions, we would need to have something like this (which I've seen on some other posts discussing comparisons):

Code: Select all

if("|txt|nfo|inf|reg|ps1|vbs|" LikeI "*|$selext|*") {load "$txt", , s; end(1)}
Thanks on the further info on not needing triple quotes with the "openwith" even when the path/name has spaces as long as we're dealing with no additional parameters. I would have tried it with single quotes myself. :whistle:

Thanks SkyFrontier, though it's not much of a script as far as complexity by any means, most importantly, it's getting a lot of use. It takes a few minutes to set it up with all programs you'd like to see come up in the various menus but once it's done, it's done and quite handy.

highend
Posts: 14597
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: [Script] WhiteSpaceCtxMenu

Post by highend »

if("|txt|nfo|inf|reg|ps1|vbs|" LikeI "*|$selext|*") {load "$txt", , s; end(1)}
LikeI was meant for comparing single entries. I personally like a regexmatch more when it comes to comparing the existence of something inside a list (but of course gettokenindex get's the job done as well). Personal preferences I think :)

Code: Select all

    $selext = "vbs";
    if (regexmatches("txt|nfo|inf|reg|ps1|vbs", "(^|\|)$selext(\||$)")) { ... }
It's not case sensitive by default and it doesn't need a leading / trailing bar in the list (which is easy to forget and renders the comparison useless compared to the Like comparison).
One of my scripts helped you out? Please donate via Paypal

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: [Script] WhiteSpaceCtxMenu

Post by SkyFrontier »

Quite flexible, indeed.
I'll try to improve it with auto-added accelerator keys.
Good news, discovered by accident: I don't necessarily need to declare CEA_ListRightClickOnWhite=6, when invoking the script via UDC, ie, I can keep both default CEA_ListRightClickOnWhite as well as WhiteSpaceCtxMenu. Sweet. :tup:
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

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 »

I'm still hoping for even more flexibility on CEA WhiteSpace, like double click on WhiteSpace in list and another for tree and also middle click WhiteSpace on List and Tree. Though I've nagged Don enough on it for now. It's coming at some point. :)

I know you're a keyboard user, but as mentioned somewhere in the thread, if you highlight file(s) with the right mouse button instead of the left, all you have to do is release the right mouse button after the highlighting and the appropriate menus will pop up. As oppose to a separate highlighting action and then a separate right click in the whitespace. It really speeds things up overall if selecting is done with the mouse, it becomes one action.

That's good news that you can trigger it with a UDC and still have another action for CEA_ListRightClickOnWhite=6

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 »

Highend, thanks for the regexmatches option. I've said too many times I've got to start learning RegEx. Time to buckle down and do it ...well maybe after the summer season. :whistle:

CookieMonster

Re: [Script] WhiteSpaceCtxMenu

Post by CookieMonster »

klownboy wrote:
CookieMonster wrote:The heredoc has single quotes the openwith as stated has triple quotes, due to the spaces in the file name, I continue to get an error on this line ?
That's because the line's not doing anything. You're specifying a menu item name and the icon to use but you have specify the action you want to take place when you click on the menu item. Please look at my post above http://www.xyplorer.com/xyfc/viewtopic. ... 60#p125998 - at the first code line. I told you that you were missing the command to open the file. Again, please look at the other examples when you add to or modify the code. You can copy that, but as explained since then, you only need single quotes not triple and don't forget the semi-colon at the end.
Sorry, I didn't read the line proceeding within the heredoc; anyways, it continues not to work ?

Code: Select all

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

Post Reply