Script to toggle list sort order

Discuss and share scripts and script files...
Post Reply
Quaraxkad
Posts: 181
Joined: 20 Apr 2014 18:01

Script to toggle list sort order

Post 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".

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

Re: Script to toggle list sort order

Post by highend »

Code: Select all

  if (get("#333")) {
    #333;
    #331;
  } else {
    #333;
    #321;
  }
?
One of my scripts helped you out? Please donate via Paypal

Quaraxkad
Posts: 181
Joined: 20 Apr 2014 18:01

Re: Script to toggle list sort order

Post by Quaraxkad »

That works, thanks!!

Quaraxkad
Posts: 181
Joined: 20 Apr 2014 18:01

Re: Script to toggle list sort order

Post 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".

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

Re: Script to toggle list sort order

Post 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.

Quaraxkad
Posts: 181
Joined: 20 Apr 2014 18:01

Re: Script to toggle list sort order

Post by Quaraxkad »

This works perfectly, thank you!

Post Reply