Page 1 of 1

Script to toggle list sort order

Posted: 28 Dec 2024 04:20
by Quaraxkad
In old versions of XY, I used to press a shortcut to toggle random list order on and off. If I remember correctly, this shortcut randomized files AND folders. Pressing it again returned the the default alpha-sort with folders on top. At some point, either that changed (or I was mistaken) to only randomize files and leaves folders on top.

I want to replicate this behavior in a script. So when the script runs, the list will toggle bwteen alpha-sorted (with folders on top) and randomized (with folders mixed). I made a script that runs #331 View | Sort By | Random Order and #333 View | Sort By | Sort Folders Apart. That works to go from sorted to random, but running it again doesn't work because Sort Folders Apart acts as a toggle and Random Order doesn't.

Is there a way to script this functionality?

EDIT: I'm probably remembering versions before this:

Code: Select all

v23.50.0205 - 2022-08-25 19:28
    + Toolbar | Random Order: Now the button's context menu features the toggle "Include 
      Folders". Tick it to also shuffle the folders.
      This setting also affects the command "View | Sort By | Random Order".

Re: Script to toggle list sort order

Posted: 28 Dec 2024 04:39
by highend

Code: Select all

  if (get("#333")) {
    #333;
    #331;
  } else {
    #333;
    #321;
  }
?

Re: Script to toggle list sort order

Posted: 28 Dec 2024 04:58
by Quaraxkad
That works, thanks!!

Re: Script to toggle list sort order

Posted: 27 May 2025 01:36
by Quaraxkad
This script works well, but there's one problem. #331 View | Sort By | Random Order does not persist when changing folders, but #333 View | Sort By | Sort Folders Apart does persist. So when I run the script once, I get a randomized file+folder listing. Then I navigate into a folder, and I get an alphabetical mix of files and folders. Rerunning the script doesn't revert to the original sort options because they're now "out of sync".

Re: Script to toggle list sort order

Posted: 27 May 2025 02:35
by jupe
If you just enable the setting you quoted at the bottom of your first post once, then this should work, and stay enabled (until toggle off) when you browse to other folders (unless they have a fvs):

if (<get sort> != "Random") { #331; } else { #321; }

Of course your default config should have sort folders apart enabled.

Re: Script to toggle list sort order

Posted: 28 May 2025 02:45
by Quaraxkad
This works perfectly, thank you!