To store permanent variable across sessions (that is, after you close and then open XY again) [Solved]

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
John_C
Posts: 336
Joined: 16 May 2018 20:04

To store permanent variable across sessions (that is, after you close and then open XY again) [Solved]

Post by John_C »

The following is a simple script that shows/hides hidden, system, and protected files in one step. It is assumed to be assigned to a user button on the toolbar.

Code: Select all

"Show Everything"
  perm $p_showHideState;
  if (!regexmatches($p_showHideState, "(1|2)")) { $p_showHideState = 1; }

  // #388 - Hide protected operating system files
  // #493 - Show hidden files and folders
  // #494 - Show system files and folders

  // Show
  if ($p_showHideState == 1) {
    if (get("#388") == 1) { #388; }
    if (get("#493") == 0) { #493; }
    if (get("#494") == 0) { #494; }
    $p_showHideState = 2;
    ctbstate(1);
  }

  // Hide
  elseif ($p_showHideState == 2) {
    if (get("#388") == 0) { #388; }
    if (get("#493") == 1) { #493; }
    if (get("#494") == 1) { #494; }
    $p_showHideState = 1;
    ctbstate(0);
  }
The script works fine except that if the button is currently in the pressed state and you close XY and then open it again and then press the button again, the script won't know that the button is already in the pressed state, and so the first time you press it, nothing will happen.

To resolve this problem, we need to preserve the value of p_showHideState between XYplorer sessions. But how?

My guess is that we can write p_showHideState and its value as a key-value pair into XYplorer.ini and then read it from there. But I don't know whether this a posssible at all and whether this way is really good.

Any suggestions?
Last edited by John_C on 06 Mar 2022 19:45, edited 1 time in total.

Horst
Posts: 1419
Joined: 24 Jan 2021 12:27
Location: Germany

Re: To store permanent variable across sessions (that is, after you close and then open XY again)

Post by Horst »

In no case to the XYplorer.ini !
For such purposes there are many scripts here which are all writing a scriptname.ini into the location of the script itself.
Windows 11 Home, Version 26H2 (OS Build 26300.9974)
Portable x64 XYplorer (Actual version, including betas)
Display settings 1920 x 1080 Scale 100%
Everything 1.5.0.1424b (x64), Everything Toolbar 3.5, Listary Pro 7.1.0.47 beta

John_C
Posts: 336
Joined: 16 May 2018 20:04

Re: To store permanent variable across sessions (that is, after you close and then open XY again)

Post by John_C »

Could you direct me to one of those scripts so that I can see how this works? :-)

Horst
Posts: 1419
Joined: 24 Jan 2021 12:27
Location: Germany

Re: To store permanent variable across sessions (that is, after you close and then open XY again)

Post by Horst »

Highend's Integration of Everything for example:
viewtopic.php?f=7&t=23224&hilit=everything
Windows 11 Home, Version 26H2 (OS Build 26300.9974)
Portable x64 XYplorer (Actual version, including betas)
Display settings 1920 x 1080 Scale 100%
Everything 1.5.0.1424b (x64), Everything Toolbar 3.5, Listary Pro 7.1.0.47 beta

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

Re: To store permanent variable across sessions (that is, after you close and then open XY again)

Post by highend »

Configuration | General | Refresh, Icons, History | Scripting | [x] Remember permanent variables

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

John_C
Posts: 336
Joined: 16 May 2018 20:04

Re: To store permanent variable across sessions (that is, after you close and then open XY again)

Post by John_C »

Thanks a lot, this works!

WirlyWirly
Posts: 332
Joined: 21 Oct 2020 23:33
Location: XY 64-Bit | Win 11 @ 100% (3440x1440)

Re: To store permanent variable across sessions (that is, after you close and then open XY again) [Solved]

Post by WirlyWirly »

I'm wanting to do something similar, I'd like to store a variable that can be accessed across XY.

XY and all my other programs are portable and stored in a folder called PortableApps. Whenever I refer to a program, I use a relative path to maintain portability.

Code: Select all

<xypath>..\..\
This relative path repeats itself in literally hundreds of places across my toolbar/CFA/scripts. I would like to turn it into an environment type variable that can be accessed throughout XY.

My current scripts look something like this...

Code: Select all

$PORTABLEAPPS = "<xypath>..\..\"

run lax("$PORTABLEAPPS\GitPortable\GitPortable.exe")
run lax("$PORTABLEAPPS\_programs_\Command\WinPython\WinPython Interpreter.exe")
...
A CFA entry might look like...

Code: Select all

; Current
"Vim";{:Text};{:Web};yml><xypath>..\..\GitPortable\Wrapper-Vim.exe

; Variable
"Vim";{:Text};{:Web};yml>$PORTABLEAPPS\GitPortable\Wrapper-Vim.exe
Anyone know how I might make this happen? Essentially I'd like to create a custom <MyVariable> like <xypath>, <xyicons>, etc...

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

Re: To store permanent variable across sessions (that is, after you close and then open XY again) [Solved]

Post by highend »

An alias would probably have been the best solution but afaik they don't work in CFAs...

The only way that comes to my mind is to set a perm variable on XY startup and use that everywhere...

But if that would be an improvement?...

XYplorer.exe /script=^|::perm $PORTABLEAPPS=resolvepath("..\..");^|

txt>::perm $PORTABLEAPPS; run lax("$PORTABLEAPPS\Notepad2_x64\Notepad2.exe" "<pfaitem>");
One of my scripts helped you out? Please donate via Paypal

Post Reply