Command: SelectEx (extended Select command)

SelectEx - a script-addin for extended "Select" functionality. It tries to combine and enhance on some (unmaintained) contributions. This add-in allows you to remove several standalone scripts from your configuration and tries to be as versatile as the native Select command already is. You can make use of popular Select switches like MAKEVISIBLE, NODESELECT, DESELECTNOMATCH e.g., just like you're used to.

Features summary:

  • automatic selection of specific items after entering a folder
  • select a single item with full path (not covered by native Select)
  • select items from clipboard, file, memory
  • store selected items to clipboard, file, memory (optional append)
  • scroll selected or checkboxed items into view (makevisible)
  • select randomly by number, size, name, type
  • select linearly by number, size, name, type
  • select by metadata (image-size or mp3-artist or just item-name e.g.)
  • select by (multiple) predefined filters (dropdown or checkboxed-list)
  • select every n-th item

Menu-Button & Preview:
SelectEx_MenuButton_v0.2.dcf (2022.01.30) (39.7 KB)
SelectEx_MenuButton_v0.1.dcf (18 KB)


Includes generic/enhanced variants of following addins:


Main command line switches:

- FROMFILE          Select items from a file (needs to be ANSI, ASCII or UNICODE (UTF16-LE))
- FROMCLIP          ..from clipboard
- FROMVAR           ..from memory/var

        Switches:
        - SKIPITEMSWITHPATH       Skip items with paths when selecting from clip/file/mem
        - SKIPITEMSWITHOUTPATH    Skip items with no path 
        - EXACT                   Like native EXACT switch (do not interpret pattern-chars)
        - GO                      Goes to folder of first item before selecting
        - USEPATH                 Select by full path instead of using names only

        Examples:
        - Select items listed in C:\Itemlist.txt
          SelectEx FROMFILE="C:\Itemlist.txt"

        - Open file by requester to select from
          SelectEx FROMFILE="{dlgopen|Choose file to select from}"

        - Go to the first path found in var "Slot01" and select items
          SelectEx FROMVAR=Slot01 GO

        - Select items from clipboard, use full qualified path for selecting
          SelectEx FROMCLIP USEPATH
- TOFILE            Save selected items to file (in UNICODE, UTF16-LE)
- TOCLIP            ..to clipboard
- TOVAR             ..to variable/memory

        Switches:
        - APPEND                  Append selection to file/clip/memvar           
        - ENCODING                Set endoding for new files (default,unicode,ascii)
        - EOL                     Specify custom characters for custom line endings (\r = CR and \n = LF)

        Examples:
        - Save selected items to C:\Itemlist.txt
          SelectEx TOFILE="C:\Itemlist.txt"

        - Save and append selected items to memvar called "Slot01"
          SelectEx TOVAR=Slot01 APPEND
- CLEARVAR          Clear the selection stored to the default variable or user defined variables.
                    Multiple variables can be cleared by separating their names with ";".
- NTH               Select every n-th item
- ITEM              Select a single item (with full path if USEPATH is used - not covered by the native Select)

        Switches:
        - USEPATH                 Select by full path instead of using name only
- RANDOM            Select items randomly (formerly known as SelectRandom add-in)
- LINEAR            Select items linear (same as RANDOM, just not random)

        Switches:
        - FOLDERS                 Select folders only
                = depthmin        limit results to folders with this minimum distance 
                = depthmax        limit results to folders with this maximum distance
                = subfldmin       limit results to folders with at least this number of subfolders
                = subfldmax       limit results to folders with this maximum number of subfolders
                = skipsubfld      exclude all (sub)folders for which the subfldmin/max criteria matched
        - FILES                   Select files only 
        - SINGLEFOLDER            Select a single folder if there are at least x numbers of folders
        - SINGLEFOLDERMINCOUNT    Number of folders, used in conjunction with SINGLEFOLDER switch
        - ITEMCOUNT               How many items to select (default is 1)
        - ITEMCOUNTRND            Select a random *number* of items
        - ITEMCOUNTPERC           How many items to select in percent
        - ACTION                  Optional action to perform ("dblclk" eg., lookup FileType ACTION command)
        - COMMANDS                Raw commands to run on selection, separate by "\n", make sure param is last
        - PATH                    External path instead of tab, use with SETVAR/SETENV (items will not be selected)
        - SETVAR                  The tab scoped var name to store chosen items (full paths), separated by "\r\n"
        - SETENV                  The process scoped env-var to store chosen items (full paths), separated by "\r\n"
        - NAME                    Filter items by name/extension (regular expression)
        - RECURSE                 Recursive mode, meant to be used with PATH
        - JSFILTER                Custom scripting filter logic (provide js-snippet)
                                  Return true to filter item and false to consider item for a random select/pick
        - JSBREAK                 Custom scripting break to stop picking/selecting items
                                  Return true to stop item picking, false to skip and null/undefined to select/pick
        - MINSIZE                 Filter files by minimum file size
        - MAXSIZE                 Filter files by maximum file size
        - MAXSIZETOTAL            Limit total size
        - COPYTOCOLL              Copy results to a dopus file collection
        - TOFILE                  Save paths of picked/selected items to file
        - APPEND                  Append mode for use with TOFILE
        - ECHO                    Output selection results to the console for easy testing

        Examples:
        - Select a random file, run the doubleclick action and make item visible
          (chooses a movie and autom. launches player eg.)
          SelectEx RANDOM FILES ACTION=dblclck MAKEVISIBLE
        
        - Select 20 images and start slideshow
          SelectEx RANDOM NAME=".*(\.jpg|png)" FILES ITEMCOUNT=20 COMMANDS=Show SLIDESHOW

        - Select 1 file out of an external folder and provide result in env- and tab-var called "SelexRnd" 
          SelectEx RANDOM FILES PATH="C:\Items" ITEMCOUNT=1 SETVAR="Result.SelectRandom" SETENV="SelexRnd"

        - Select 50% of files:
          SelectEx RANDOM FILES ITEMCOUNTPERC=50

        - Select a single file, or a single folder if there are at least 3 subfolders present. This can be used
          for a button that when repeatedly pressed, opens random folders and eventually "doubleclicks" a file.
          SelectEx RANDOM FILES SINGLEFOLDER ACTION=dblclk

        - Fetch 10 random "NewAge" tracks from "D:\music" and store them in a new collection called "NewAge"
          (Notice: using the RECURSE switch takes some time for heavier music collections).
          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('SelectEx RANDOM ITEMCOUNT=10 '+
              'PATH="D:\\music" RECURSE JSFILTER="'+jsFilter+'" COPYTOCOLL=NewAge');

        - Select a maximum number of 100 random folders or total size of 8gb
          SelectEx RANDOM MAXSIZETOTAL=8gb FOLDERS ITEMCOUNT=100

        - Select the first 100 folders (not random, top to bottom)
          SelectEx LINEAR ITEMCOUNT=100 FOLDERS
        
        - Select 8gb of items, that are larger than 1mb (not random, top to bottom)
          SelectEx LINEAR MAXSIZETOTAL=8gb MINSIZE=1mb
- AUTO              Trigger auto-selection (simulate onafterfolderchange event)
- SIMILARMETA       Select files with similar meta data
- SIMILARMETAJS     Select files with similar meta data using a jscript snippet

        item = item to test for selection (will represent every item in src or dst (if INDEST is used).
        selItem = first selected file (DO item)
        selItems = collection of all selected files (DO items)
        cmd = command object to be used

        Switches:
        - INDEST                  Apply selection to destination lister or tab

        Examples:
        - Select all images, that have the same height and width as the currently selected image
          SelectEx SIMILARMETA="metadata.image.picheight;metadata.image.picwidth"

        - Select items with same name as the currently selected (looking at the first 8 chars only)
          SelectEx SIMILARMETAJS="return selItem.name.left(8)==item.name.left(8);"

        - Select all wma-files for which their actual filename does not match their track and artist information.
          The filename matched against here is "<track> - <title>.wma", "03 - The Songtitle.wma"

          SelectEx SIMILARMETAJS="if (item.name.search('0?'+item.metadata.audio_text.mp3track+
          ' \- '+item.metadata.audio_text.mp3title+'\.wma')!=0) return true;"

        - Select all files, for which the title-tag cannot be found in the filename (case-sensitive)
          SelectEx SIMILARMETAJS="if (item.name.indexOf(item.metadata.audio_text.mp3title)==-1) return true;"
- FILTERDROP        Un/select, un/hide items by choosing a filter from a dropdown
- FILTERLIST        Un/select, un/hide items by choosing (multiple) filters from a list
        = <select>                Select items by chosen filter (default)
        = deselect                Deselect items..
        = hide                    Hide items..
        = hidenomatch             Hide nonmatching items..

        Whenever a filter is set, a tab-scoped variable "Script.SelectEx.FilterEnabled" and "Script.SelectEx.FilterEnabled.bfc.drop"
        is created to allow buttons to indicate a set filter status and the Autovar addin to clear vars and status automatically.

Global switches:

- MAKEVISIBLE       Scroll selected items into view
        = checked   Scroll checkboxed items into view if present

- NODESELECT        Do not deselect selected items
- DESELECTNOMATCH   Deselect items that are not affected
- PT                Switches and options to PassThrough to the native Select command
- NOFAIL            Will never return failure (makes buttons run following commands in error situations)

- XLOG              Level of output, defaults to normal, which means important information only
        = off,xit,err,inf,warn,<normal>,trace,dump

Auto-Selection:
Auto-Selection of items when entering folders needs to be enabled and configured in the config section.
You can use aliases, regular paths or regular expressions to restrict automatic selection of items to specific folders. You can use regular item names or regular expressions again to define the items to be selected, use REGEX= prefix as shown. The dialog also allows to toggle the MakeVisible feature, which takes you to the first auto-selected item automatically.


Installation:
To install the command, download the *.js.txt file below and drag it to Preferences / Toolbars / Scripts.

Trouble-Shooting:
In case you encounter errors, add XLOG=dump to your commandline or raise the global log level in the script config.
Then re-do what failed and post the result (output) right here! o)

cya,
tb

Download:
v.0.5.8 - 2021.03.07 - fix ftp path handling
Command.Generic_SelectEx.js.txt (158.4 KB)

v0.5.7 - 2018.09.04 - add "selItems" (all selected files) to be used in SIMILARMETAJS/jsCompare()
Command.Generic_SelectEx.js.txt (154.9 KB)

v0.5.6 - 2017.11.27 - USEPATH switch by default for MAKEVISIBLE

v0.5.5 / 2017.09.01 - fix for files not being created if APPEND was used
Command.Generic_SelectEx.js.txt (153.8 KB)

v0.5.4 / 2016.11.01 - added ENCODING and EOL options, resolving and fixes
Command.Generic_SelectEx.js.txt (153 KB)

v0.5.3 / 2016.05.08 - added NOFAIL and CLEARVAR and fixes
Command.Generic_SelectEx.js.txt (146 KB)

v0.5 / 2015.07.03 - added TODEST, enhanced FOLDERS and added new script-config "AutoSelect.Actions":
Command.Generic_SelectEx.js.txt (141 KB)

v0.4.5 / 2015.06.11 - changes to AUTO (auto-selection triggered by command line):
Command.Generic_SelectEx.js.txt (130 KB)

9 Likes

No file is selected for me with FROMCLIP and FROMFILE... Filenames are display in log but no selection.
If I put fullpath in text file or clipboard, it's ok.

So the problem is with only names in the file or clipboard for you? It works for me, but let's see what's happening on your side.
Can you post the log-output, the "SelectEx" commandline you used and maybe the file/clipboard content as well?

You can see that only files with fullpath are selected.
Same thing for command SelectEx FROMCLIP.


Strange thing...
If files to select are in root (e.g. c:\), only files with filename in text file are selected.
If files to select are in folder (e.g. c:\test), only files with fullpath in text file are selected.

The "strange thing" is, because DOs path object returns a trailing slash for rootfolders and not for regular subfolders. I forgot about that fact and so building a valid path can fail. It'll be fixed of course and some other problems I discovered for flatview.

Thanks a lot for taking the time to post these details, I was able to reproduce easily with that! o) And sorry that this first shot did not hit dead center! o)

It'a a pain that, but almost everything will do it, not just the Opus path object, since C: and C:\ mean very different things. All thanks to the awful design decisions in DOS.

What do you mean with "but almost everything will do it, not just the Opus path object"..?

I don't really get your words, is there irony in there? In case there is and you got me wrong, I just blame myself for not testing thoroughly enough. No offense meant, I have good times doing DO commands! o)

Outside of special cases, anything written for Win32 which doesn't put give you C:\ for the parent of a folder below the C drive is wrong.

C: on its own is not a synonym for C:\

This is unlike C:\Windows which is a synonym for C:\Windows\ -- the root folders are special because in DOS C: means "the last folder you CD'd to on the C drive", which is held over into parts of Windows.

And, yeah, it's a pain and leads to bugs because you have to treat it as a special case a lot of the time.

For completeness sake.
C:\ = the root folder of C:

If C:'s active folder is C:\tmp:
C: = C:\tmp
C:Data.txt = C:\tmp\data.txt
C:Test\data.txt = C:\tmp\Test\data.txt

@leo, as illustrated above, I think it makes sense, in a relative path kind of way.

Btw, you can use GetFullPathName to expand all of the above to proper paths.
(may be useful for the Path object and FSUtil.Resolve, or maybe as a FSUtil function).
Note, the buffer length is in TCHARs, not bytes.

Updated to v0.3:

  • new feature "Auto Selection" of items after entering a folder

  • new feature "ITEM", select item (supports full paths if the USEPATH switch is used, which doesn't work with the native select)

  • new feature "TOCLIP", save current selection to clipboard

  • new feature "TOFILE", save current selection to file

  • new feature "TOVAR", save current selection to memory (persistent storage)

  • new feature "FROMVAR", load selection from memory

  • new feature "NTH", select every n-th item

  • new feature "RANDOM", select items randomly (formerly known as SelectRandom script command)

  • new feature "LINEAR", select items linear (same as RANDOM, but not random o)

  • new feature "AUTO", trigger for autoselection (simulate onafterfolderchange)

  • new feature "SIMILARMETA", select files with similar meta data

  • new feature "SIMILARMETAJS", select files with similar meta data using a jscript snippet

  • new feature "FILTERDROP", un/select, un/hide items by choosing a filter from a dropdown

  • new feature "FILTERLIST", un/select, un/hide items by choosing (multiple) filters from a list

  • new switch "SKIPITEMSWITHPATH", skip items with paths when selecting from clip/file/mem

  • new switch "SKIPITEMSWITHOUTPATH", skip items with no path when selecting from clip/file/mem

  • new switch "USEPATH", select by full path instead of using only the names from clip/file/mem

  • new switch "PT" = pass through, to pass arguments through to the native select command

  • new switch "DESELECTNOMATCH", works like native DESELECTNOMATCH switch (deselects first)

  • new switch "NODESELECT", works like native @nodeselect modifier

  • new switch "APPEND", append selected items to files, memorized-variables, clipboard

  • new switch "GO", switches folder to the first item in clip/file/memory before selecting

  • new switch "MAKEVISIBLE", works like native MAKEVISIBLE switch (scroll into view), but can also be used "standalone"

  • new switch "EXACT", works like native EXACT switch (do not interpret pattern-chars)

  • new switch "XLOG", enable output and set level (defaults to normal if no value given)

Updated to v0.4:

  • removed unused code, minor tweaks
  • option "SETTABVAR" renamed to "SETVAR"
  • option "SETENVVAR" renamed to "SETENV"
  • new feature "FROMVARDROP" to easify picking of memorized selections

For easy exploring of what SelectEx can do, I uploaded a menu button that provides some of the features.

@Albator
The issue you encountered is fixed in the meantime of course! o)

Thank you kinda, tbone, for all the scripting support you offer the community. People like myself, that don't know the first step to coding, really appreciate all the effort you and others do to write us some very useful and powerful scripts to add to the usability of Dopus.

Thanks for also adding a sample button. Nothing helps more than have sample code snippets or a button filled with sample buttons to show what we can do.

To all the Dopus programmers and script coders :thumbsup:

We really do appreciate you guys! :smiley:

Updated to v0.4.1:

  • no need for a selected item when using SIMILARMETAJS

This new "feature" (I actually just removed 2 lines), allows to select without necessarily comparing data with another item.

Example 01:
This selects all wma-files for which their actual filename does not match their track-number, artist information tags.
The filename matched against in this usecase is " - .wma" -> "03 - The Songtitle.wma"

SelectEx SIMILARMETAJS="if (item.name.search('0?'+item.metadata.audio_text.mp3track+' \- '+item.metadata.audio_text.mp3title+'\.wma')!=0) return true;"

Example 02:
This would select all files, for which the title-tag cannot be found in the filename (case-sensitive):

SelectEx SIMILARMETAJS="if (item.name.indexOf(item.metadata.audio_text.mp3title)==-1) return true;"

@ktbcrash
I can't say I mind your kind feedback! o) Thank you! o)

Hi tbone,
many thanks for this great script.
I played around with the JSFILTER argument and tried to achieve the following:

Randomly select 1 hour of music files (???) containing the tag "My Tag" (argument JSFILTER) from a specified folder (argument PATH) and write the result to the file /temp\playlist.m3u (argument TOFILE).

At the moment I'm able to select e.g. 20 tagged files but not 1 hour. Would it be possible to create such a Filter based on mp3songlength? I tried and couldn't get it working. I'd really appreciate any help with this.

Since TOFILE doesn't work together with PATH I have to use the arguments COPYTOCOLL=MyColl and COMMANDS=Go coll://MyColl followed by Select ALL and a second SelectEx line to get the playlist created. It would be nice to have TOFILE working with PATH.

My JSFILTER-snippet to select audio files based on a specific tag:

var jsFilter = ""+
	"var tagstring = '';"+
		"if (item.metadata == 'audio'){ "+
			"for (var tagEnum = new Enumerator(item.metadata.tags);"+
				"!tagEnum.atEnd();"+
				"tagEnum.moveNext() ) {"+
					"tagstring += tagEnum.item();"+
					"tagstring += ','; }"+
			"if (tagstring.indexOf('My Tag') !=-1) return false;"+
		"}";

Updated to v0.4.2:

  • distance() function added for simple fuzzy selections with "SIMILARMETAJS"
  • new option "JSBREAK" for custom rules on when to stop item selection/picking
  • "TOFILE" and "APPEND" now also work in conjunction with "RANDOM"/"LINEAR"

@Kundal
Thanks for giving SelectEx a spin and pushing the limits! o))
Here is a JSBREAK example and code that stops the item picking if a total mp3-duration of 30 minutes has been reached.
The try-catch block at the start initialises the global "totalDuration" variable, which is re-used by the rest of the snippet.

SelectEx RANDOM ITEMCOUNT=99 JSBREAK="try{totalDuration;}catch(e){totalDuration=0;} if ((totalDuration+item.metadata.audio.mp3songlength)>60*30) return true; totalDuration+=item.metadata.audio.mp3songlength;" TOFILE="C:\MyPlaylist.txt

Wow!
I knew you would make me happy but I didn't expect it so fast. "JSBREAK" and "TOFILE" are working fine for me now.
Many many thanks!

You're welcome! o)
As "duration" is quite a sensible thing to select on, I consider adding min/max/totalduration switches in the future. Similar to the existing min/max/totalsize feature. Having to use js-snippetting is probably not everyones first choice I guess, but still good to have for all the special cases. o))

Yes, in my case it would be much easier if instead of JSFILTER the native FILTER=MyFilter argument and/or FILTERDROP/FILTERLIST could be used together with RANDOM/PATH/ITEMCOUNT/... :wink:

Very nice script. Some more options and it's an own app, which should get a GUI :wink:.

A GUI for Random (audio) would be nice... where you can select all meta-options, size, etc. and also save some presets.