GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Command: SelectRandom (randomly select files/folders)


#1

SelectRandom - a script command which allows you to randomly select items by type, count, size, total-size or some other filters. Results can be selected, dumped to console, copied to file collections or returned in env/tab-variables.

“SelectRandom” is obsolete and won’t receive any updates.
The functionality of this command has been moved into “SelectEx”. Find it here: resource.dopus.com/viewtopic.php?f=35&t=24414
Read this quick-tip on how to update an existing button: resource.dopus.com/viewtopic.php … 42#p133046

Why:
I made this…

  • to create a random selection of mp3 albums to listen to
  • to select random albums/images to view in a slideshow
  • because I have fun doing it… o)

Params and Features:
FOLDERS - select folders only (default is files or folders)
FILES - select files only (default is files or folders)
NODESELECT - do not deselect items (useful for keeping the selection or adding single items each run)
RANDOM - select a random number of items
SINGLEFOLDER - select a single folder if there are at least SINGLEFOLDERMINCOUNT numbers of folders
SINGLEFOLDERMINCOUNT - number of folders, used in conjunction with SINGLEFOLDER switch
ITEMCOUNT - how many items to select (default is 1)
ITEMCOUNTPERC - how many items to select in percent
ACTION - optional action to perform (“dblclk” eg., lookup FileType ACTION command and options)
COMMANDS - raw commands to run on selection, separate by “\n”, make sure param is last
PATH - use external path instead of tab, meant to be used with SETTAB/ENVVAR (items will not be visually selected)
SETTABVAR - the tab scoped variable name, containing chosen items (full paths), separated by ";"
SETENVVAR - the process scoped env-variable name, containing chosen items (full paths), separated by ";“
NAME” - filter items by name/extension (regular expression)
RECURSE - recursive mode, meant to be used with PATH
JSFILTER - for custom scripting filter logic
MINSIZE - to filter files by minimum file size
MAXSIZE - to filter files by maximum file size
MAXSIZETOTAL - to limit total size
COPYTOCOLL - copy results to a file collection
ECHO - output results to the console for easier testing

If you have trouble using it, the script config section offers a trigger to enable some console output, if that does not help, just ask! o)

Hint:
For selecting a single item out of many, it is recommended to run “ScrollSelectionIntoView” after running “SelectRandom”, to scroll the selected item into the visible area. Find it right here: [Command: ScrollSelectionIntoView)

Examples - Usecases:
Select 10 random music albums folders and add these to winamp:

SelectRandom FOLDERS ITEMCOUNT=10 COMMANDS=WinampAddItemsSelect a random file, run the doubleclick action and make item visible (chooses a movie and autom. launches player eg.)

SelectRandom FILES ACTION=dblclck COMMANDS=ScrollSelectionIntoViewSelect 20 images and start slideshow

SelectRandom FILES ITEMCOUNT=20 COMMANDS=Show SLIDESHOWSelect 1 file out of an “external” folder and provide result in an env- and tab-var called “Result.SelectRandom”

Examples - some more:
Select a random item:SelectRandomSelect 10 random items:

SelectRandom ITEMCOUNT=10Select 10 random folders:

SelectRandom FOLDERS ITEMCOUNT=10Select 50% of files:

SelectRandom FILES ITEMCOUNTPERC=50Select a random number of random items:

SelectRandom RANDOMSelect 1-5 random items:

Select a single file, or a single folder if there are at least 3 subfolders present.
This creates a button that when repeatedly pressed, opens random folders and eventually “doubleclicks” a file

Another Demo:
Select 50% of items



Installation:
To install the command, download the *.js.txt file below and drag it to Preferences / Toolbars / Scripts.
After that the command shall be ready to use in buttons, scripts and externally from dopusrt.exe of course.

cya,
tbone

Download:

[ul][li]Latest: v0.3 / 2015.04.19 - new features "NAME, “RECURSE”, “JSFILTER”, “MIN/MAXSIZE”, “MAXSIZETOTAL”, “COPYTOCOLL”, “ECHO”:
Command.Generic_SelectRandom.js.txt (37.1 KB)
[/li]
[li]v0.2 / 2015.04.16 - new options “PATH”, “SETENVVAR”, “SETTABVAR”:
Command.Generic_SelectRandom.js.txt (19.4 KB)
[/li]
[li]v0.1.1 - support for updates/scriptwizard:
Command.Generic_SelectRandom.js.txt (6.76 KB)
[/li]
[li]v0.1 - initial version:
Command.Generic_SelectRandom.js.txt (5.7 KB)[/li][/ul]


Command: SelectEx (extended Select command)
Create folder.jpg on selected folders
My Dark Color Theme (Opus 12 [VERSION 3] update)
#2

This is awesome. Thanks for sharing, tbone!
:thumbsup:


#3

I thank you! o) Do you have a usecase already? I’m curious on other peoples ideas in conjunction with random selections. In case there’s something I can add, let me know as well. o)


#4

Mainly for random music. Great to go into flat view, hit a button to select random songs to listen to.

My second case would be for selecting a random thumbnail for a folder. Sometimes it’s really hard picking from hundreds of images for a really good thumbnail to represent a folder. Now I can click a button and let it randomly pick for me. If I don’t like it, I can click again :slight_smile: Making a copy of the selected image, naming it folder.jpg and hiding it, is easy. Might need a third party program to auto crop the image to a 1:1 aspect ratio. Not sure Dopus can do the cropping to square. Something I figure out later.

I haven’t had time to fully sit down and code the buttons I want so not sure if it’s missing anything. The only thing I was hoping for was an “About” screen that showed a click-able link to this post so I could look up your example buttons later without bookmarking it. Seems like a nice way to always link back to your original post :slight_smile:

I’ve been waiting for a random select script for a long time now. So far I’ve only tested with your example buttons and it seems to work perfectly. I’ll figure out what I really want my buttons to be when I have more time.

Thanks again for creating and sharing!


#5

Love this script, it is really useful when I don’t have an idea what to watch, read or listen to.

I would like to suggest adding extension-filtering (useful for excluding .txt, .db, .exe, .nfo, .js, .vbs and so on), and
a MAKEVISIBLE parameter. The latter should simply add " MAKEVISIBLE" to the select command.

I don’t think I’m alone having thumbs.db, batchfiles, etc somewhere in the flat view.
Then there are those extensions that isn’t fun executing by accident when using this command (tied to a hotkey):

SELECTRANDOM FILES ACTION=dblclk

#6

I agree, filtering for extensions is something I also had in mind. While it’s not availabe within this command, you probably can get around by setting a show filter in the same button right before SelectRandom runs? I did not try that though, places where I use SelectRandom are kind of “unmixed”. o) Will see, if I can add that nonetheless.


#7

Nice script, very useful for random media-playlists.

I have two other ideas:

  • Select max. x MB (e.g. 4,5 GB for fitting on DVD)
  • Select music-tags (like genre and year)

I would do myself if my scripting skills would be good enough. :cry:


#8

I understand the wish for a random, but size-limited selection, but to get a random selection based on genres, years or something else, some heavier interaction with a GUI is required I guess, so what about using the Find-Utility to get a list of items (by searching for genre x,y,z and year 1,2,3 et.c) and then run SelectRandom on that find result? That sounds like it should do the trick, what do you think?


#9

Yes, good idea!


#10

Updated to v0.2:

  • new option “PATH”, to choose items from any folder
  • new option “SETENVVAR”, the given env-var will contain item-paths
  • new option “SETTABVAR”, the given tab-var will contain item-paths

The new options allow to “select” from an external folder in which case the results can be put into variables to be used by scripts or buttons in different ways. The random item selection is not done visually in the filedisplay in this case.

This snippet demonstrates how to choose a random item from C:\Windows and print its name into the script console.

[code]var cmd = data.func.command;
cmd.RunCommand(‘SelectRandom PATH=“C:\Windows” ITEMCOUNT=1 SETTABVAR=“Tab.SRResult” SETENVVAR=“Env.SRResult”’);

DOpus.Output("TabResult: " + data.func.sourcetab.Vars.Get(“Tab.SRResult”));
DOpus.Output("EnvResult: " + new ActiveXObject(“WScript.Shell”).Environment(“Process”)(“Env.SRResult”));[/code]


#11

Updated to v0.3:

  • new option “NAME” to filter items by name/extension (regular expression)
  • new option “RECURSE” recursive mode, meant to be used with PATH
  • new option “JSFILTER” for custom scripting filter logic
  • new option “MINSIZE” to filter files by minimum file size
  • new option “MAXSIZE” to filter files by maximum file size
  • new option “MAXSIZETOTAL” to limit on total size (ITEMCOUNT precedes)
  • new option “COPYTOCOLL” to copy results to a file collection
  • new switch “ECHO” to output results to the console for easier testing

You can now filter what get’s selected/chosen by name/extension (NAME option) and item size (with MIN/MAXSIZE).
To select 8GB of files, use the new MAXSZIZETOTAL option. All size-related options support friendly sizes like “1mb” or “0.5gb” etc. Foldersizes will be taken into account and determined automatically if required.

There’s also an option to pass a snippet of js-code to allow for custom filtering. You can create queries that randomly select files by mp3-genre e.g. This example fetches 10 random “NewAge” tracks from D:\music and stores them in a new collection called “NewAge” (notice: using the RECURSE switch takes some time for heavier music collections).

[code]var jsFilter = “”+
“if (item.metadata == ‘audio’){ “+
“var genre = new String(item.metadata.audio[‘mp3genre’]);”+
“if (genre.indexOf(‘New Age’)!=-1) return false; /do not filter/”+
”}”;

cmd.RunCommand(‘SelectRandom ITEMCOUNT=10 PATH=“D:\music” RECURSE JSFILTER="’+jsFilter+’" COPYTOCOLL=NewAge’);[/code]
A major cleanup has been done, if you like an example on how to defrag your code, take a look. I think it’s quite nice! o)


#12

“SelectRandom” is obsolete and won’t receive any updates.
The functionality of this command has been moved into “SelectEx”. Find it here: Command: SelectEx (extended Select command)

Any SelectRandom call/button can be updated to work with SelectEx by turning:

SelectRandom <your options here> into

Thanks! o)