Toggle a Configuration Setting Using a Script

Discuss and share scripts and script files...
soldier9599
Posts: 10
Joined: 16 May 2014 02:43

Toggle a Configuration Setting Using a Script

Post by soldier9599 »

I would like to be able to write scripts that toggle configuration settings, but I can't figure out any syntax relating to this. Specifically, I am currently interested in creating a custom hotkey and toolbar button that toggle between 32 and 64 bit context menus. Is this possible? I have coding experience, but I only started using XYplorer a few days ago so I'm a bit lost. So far I've done a "hello world" and that's it. I have figured out how to make a custom toolbar button run a script and how to set a hotkey to a UDC, but I can't figure out how to edit configuration settings using scripts. Any help would be appreciated.

I realize there is an option to view the 64-bit context menu in the 32-bit context menu, but I'd rather just have a toggle switch if possible. Ideally, I would have one combined context menu with all of the options, but I'm assuming that's not possible, am I right? Also, I'm not looking to alter the XYplorer.ini file. That would just be a change the initialization settings and require restarting the program to take effect. I'm trying to toggle the setting as if I went into configuration and altered the value currently saved into RAM.

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

Re: Toggle a Configuration Setting Using a Script

Post by admin »

Hi and welcome!

This is currently not possible, but I think it can be useful, so I will make it accessible via the non-documented tweak() command in the next beta. It will work like this:

Code: Select all

        tweak("ContextMenu64", ""); // toggle
        tweak("ContextMenu64", 1); // on
        tweak("ContextMenu64", 0); // off
        echo tweak("ContextMenu64"); // get state      
Don

PeterH
Posts: 2826
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Toggle a Configuration Setting Using a Script

Post by PeterH »

Code: Select all

   echo tweak("ContextMenu64", 1); // set on and get previous state? 
:?:

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

Re: Toggle a Configuration Setting Using a Script

Post by admin »

Yes, and the question is...?

PeterH
Posts: 2826
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Toggle a Configuration Setting Using a Script

Post by PeterH »

admin wrote:Yes, and the question is...?
...will this be possible? (Setting the setting *and* getting the old value.)

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

Re: Toggle a Configuration Setting Using a Script

Post by admin »

Yes, it IS possible already now. :)

PeterH
Posts: 2826
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Toggle a Configuration Setting Using a Script

Post by PeterH »

admin wrote:Yes, it IS possible already now. :)
Then it's no question :lol:

soldier9599
Posts: 10
Joined: 16 May 2014 02:43

Re: Toggle a Configuration Setting Using a Script

Post by soldier9599 »

Thanks! This is perfect.

I worked with it a bit to make it so on left click my button would toggle, and on right click it would allow me to choose the state or check the state with easy to understand English language text.

My left click code is just the toggle state line you have:

Code: Select all

tweak("ContextMenu64", ""); // toggle
Here is my right click code:

Code: Select all

"Enable 64-bit Menu"
 tweak("ContextMenu64", 1); // on
"Enable 32-bit Menu"
 tweak("ContextMenu64", 0); // off
"Check State"
 if (tweak("ContextMenu64") == 0) {
  echo "32-bit menus are activated.";
 }
 elseif (tweak("ContextMenu64") == 1) {
  echo "64-bit menus are activated.";
 }

driftingnarwhal
Posts: 3
Joined: 03 Jun 2020 00:17

Re: Toggle a Configuration Setting Using a Script

Post by driftingnarwhal »

Hello I'm trying to use the tweak command to make a toggle to set whether folders are sorted separately or not, but I'm getting an error that SortFoldersApart is not supported by tweak. Is there a reason that it's not supported?

Here's what I'm using as my script to run on left click:
tweak("SortFoldersApart", "");

Thanks for your help!
Last edited by driftingnarwhal on 06 Mar 2022 01:58, edited 1 time in total.

jupe
Posts: 3292
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Toggle a Configuration Setting Using a Script

Post by jupe »

tweak only supports a limited set of commands, what you want to do can be done like this though:

settingp "SortFoldersApart", 1; and to turn off settingp "SortFoldersApart", 0;

you'll need to add to the script if you want to make it toggle.

driftingnarwhal
Posts: 3
Joined: 03 Jun 2020 00:17

Re: Toggle a Configuration Setting Using a Script

Post by driftingnarwhal »

Okay thank you so much!!

jupe
Posts: 3292
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Toggle a Configuration Setting Using a Script

Post by jupe »

Actually sorry, you can make it a toggle using this command #333; instead.

driftingnarwhal
Posts: 3
Joined: 03 Jun 2020 00:17

Re: Toggle a Configuration Setting Using a Script

Post by driftingnarwhal »

Even better. Thanks again for the help!

xy123
Posts: 208
Joined: 17 Sep 2017 11:46
Location: Win10 64-bit, @100%

Re: Toggle a Configuration Setting Using a Script

Post by xy123 »

soldier9599 wrote: 20 May 2014 20:03 My left click code is just the toggle state line you have:

Code: Select all

tweak("ContextMenu64", ""); // toggle
I get "Key 'ContextMenu64' is not supported by Tweak". Something changed?
jupe wrote: 06 Mar 2022 02:01 tweak only supports a limited set of commands

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

Re: Toggle a Configuration Setting Using a Script

Post by highend »

One of my scripts helped you out? Please donate via Paypal

Post Reply