Page 1 of 1

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

Posted: 06 Mar 2022 17:09
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?

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

Posted: 06 Mar 2022 17:44
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.

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

Posted: 06 Mar 2022 17:54
by John_C
Could you direct me to one of those scripts so that I can see how this works? :-)

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

Posted: 06 Mar 2022 18:39
by Horst
Highend's Integration of Everything for example:
viewtopic.php?f=7&t=23224&hilit=everything

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

Posted: 06 Mar 2022 18:52
by highend
Configuration | General | Refresh, Icons, History | Scripting | [x] Remember permanent variables

Done^^

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

Posted: 06 Mar 2022 19:45
by John_C
Thanks a lot, this works!

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

Posted: 16 Apr 2022 04:18
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...

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

Posted: 17 Apr 2022 08:33
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>");