Command: SelectEx (extended Select command)

@tbone: Sorry if these ideas were already discussed above (I've already exceeded my procrastination-time/-budget reading the Opus forum by a solid 3–4 hours today). :crazy_face:

I have two suggestions for improvement of SelectEx:

  1. There's no indication that filters activated by SelectEx, are in fact engaged, which can lead to confusion since it's easy to think that there are no items in a folder, when there are. On the other hand, if I use DOpus own filter bar, I have a different background color going on in the file list (see screenshot). Is it possible to achieve such background color or at least some sort of "filters are in play" indication with SelectEx?

  1. Resizable multi-filter list, preferably auto-resized to show all your filters (possibly too complicated)?

Snag_118aa96

Thanks for all your great Opus contributions!

Hello!
Would it be possibile to add MAXLENGHTTOTAL, so I can randomly select from a music folder setting the total length of the files? ie:
To select 1 hour of music -> MAXLENGTHTOTAL = 60min

Thanks!

@H-Ce

  1. The DO team would need to add support for different background if filter is active.
  2. This specific dialog cannot be changed in size, I would need to rebuild it to support resizing. Alternatively the DO team could allow resizing by supporting the want_resize property on the "dlg.choices" type of dialogs.

@ElimGarak
You could try the SIMILARMETAJS keyword and provide custom js-code to do the mp3 total length calculation I assume.

Hi tbone,

I'm using this script to randomly , that you kindly made for me more than 4 years ago. :smiley:
It randomly selects some music files (based on total size and number) from a folder, copy them into another folder and then cut and paste the original ones to another one.

function OnClick(data){
   var PoolFolder = DOpus.Dlg.Folder("Seleziona cartella sorgente", "H:\\00000000 Magicompilation\\Pool");
   var MoveFolder = DOpus.Dlg.Folder("Seleziona cartella destinazione", "J:\\AAA SPOTIFY");
   var CopyFolder = PoolFolder+"\\Copiati";

   var cmd = data.func.command, tab = data.func.sourcetab; tab.Vars.Set("SexRes") = "";
   cmd.RunCommand('SelectEx XLOG=all RANDOM FILES PATH="'+PoolFolder+'" MAXSIZETOTAL=40Mb ITEMCOUNT=10 SETVAR="SexRes" ECHO');
   var strFiles = tab.Vars.Get("SexRes"); if (strFiles=="") return;
   var arrFiles = strFiles.split("\n"), cmd = DOpus.Create.Command();
   for(var i=0;i<arrFiles.length;i++) cmd.AddFile(arrFiles[i]);
   
   cmd.AddLine('CreateFolder "'+CopyFolder+'" READAUTO=no NOSEL');
   cmd.AddLine('Copy TO "'+CopyFolder+'"');
   cmd.AddLine('CreateFolder "'+MoveFolder+'" READAUTO=no NOSEL');
   cmd.AddLine('Copy MOVE TO "'+MoveFolder+'"');
   cmd.Run();
}

How can I adapt it to use the total length of music files instead of total size? I'm sorry, but I'm quite as ignorant as 4 years ago.

You could have learned to write some code in the meantime!? o)

Run this command at some place containing mp3s, it should select random files, not exceeding 1800 seconds playtime in total. Then incorporate this command into what you already have. Don't expect this to work all the time, very basic error handling here, actually it's rather missing completely. o)
You can remove the "DOpus.Output(len + ' ' + item.name); " piece, just for testing. Watch single quote vs. double quote usage and maybe use escaping with "\", when injecting this into the button code you already have.

SelectEx RANDOM ITEMCOUNT=999 FILES JSBREAK="if (typeof len == 'undefined') len=0; DOpus.Output(len + ' ' + item.name); mp3len = item.metadata.audio.mp3songlength; if (isNaN(mp3len)) return false; len+=mp3len; if (len>1800) return true;"
1 Like

First of all, thank you!

Frankly, I don't even know where to start. I've tried running the command and I've got a parsing error.
image
And I don't have ANY idea how to inject this in the button code.
I'm sorry. If you have a videogame to translate from English into Italian, I'm your man. But this is way beyond me.
If you don't have time, I perfectly understand and don't worry at all. Thanks anyway!

Run it as a normal command, not in script mode.


"Not recognized as internal or external command, executable program or batch file".

As an Opus command. It won't be recognised from outside of Opus.

I.e. Put it in an Opus button or hotkey, or into the editor you had in your previous screenshot, but don't turn on script mode in the button/editor.

Thank you! Yes, it works. But now I don't know how I can modify my button script to incorporate this. :slight_smile:

Please do some research on the forum or the documentation. Editing a button is such a basic task in DO, we should not cover that here. Consider to open a new thread in the general section if you cannot figure this out.

The latest beta automatically makes these dialogs resizable.

Thank you! o)

@H-Ce
There you go. o)

Hi, I'm sorry I didn't make my point.
I know how to edit a button. I don't know how to edit the code in my button to have the script do what I want. Now it randomly selects some music files (based on total size and number) from a folder, copy them into another folder and then cut and paste the original ones to another one. I'd like to change it to select depending on totale length using the command you provided.

Basically, how should I change this:

function OnClick(data){
var PoolFolder = DOpus.Dlg.Folder("Seleziona cartella sorgente", "H:\00000000 Magicompilation\Pool");
var MoveFolder = DOpus.Dlg.Folder("Seleziona cartella destinazione", "J:\AAA SPOTIFY");
var CopyFolder = PoolFolder+"\Copiati";

var cmd = data.func.command, tab = data.func.sourcetab; tab.Vars.Set("SexRes") = "";
cmd.RunCommand('SelectEx XLOG=all RANDOM FILES PATH="'+PoolFolder+'" MAXSIZETOTAL=40Mb ITEMCOUNT=10 SETVAR="SexRes" ECHO');
var strFiles = tab.Vars.Get("SexRes"); if (strFiles=="") return;
var arrFiles = strFiles.split("\n"), cmd = DOpus.Create.Command();
for(var i=0;i<arrFiles.length;i++) cmd.AddFile(arrFiles[i]);

cmd.AddLine('CreateFolder "'+CopyFolder+'" READAUTO=no NOSEL');
cmd.AddLine('Copy TO "'+CopyFolder+'"');
cmd.AddLine('CreateFolder "'+MoveFolder+'" READAUTO=no NOSEL');
cmd.AddLine('Copy MOVE TO "'+MoveFolder+'"');
cmd.Run();
}

to implement this:

SelectEx RANDOM ITEMCOUNT=999 FILES JSBREAK="if (typeof len == 'undefined') len=0; DOpus.Output(len + ' ' + item.name); mp3len = item.metadata.audio.mp3songlength; if (isNaN(mp3len)) return false; len+=mp3len; if (len>1800) return true;"

Thanks!

So you know how to edit a button. You also know the button makes use of "SelectEx" command. You probably also know, commands use parameters. Now find SelectEx command in the button code and change/append necessary parameters. This is no rocket science! o)

//change this line
cmd.RunCommand('SelectEx XLOG=all RANDOM FILES PATH="'+PoolFolder+'" MAXSIZETOTAL=40Mb ITEMCOUNT=10 SETVAR="SexRes" ECHO');
//to be this..
cmd.RunCommand('SelectEx PATH="'+PoolFolder+'" RANDOM FILES ITEMCOUNT=999 SETVAR="SexRes" JSBREAK="if (typeof len == \'undefined\') len=0; mp3len = item.metadata.audio.mp3songlength; if (isNaN(mp3len)) return false; len+=mp3len; if (len>1800) return true;" XLOG=all ECHO'); 

Not tested! o)

It worked, thank you so much and... to me it IS rocket science. :smiley:

Glad to hear. o)
In case you did not notice the "1800" in the command line, it represents the total playtime in seconds, adjust as necessary.

Hello! Here I am again with one of my usual annoying requests (if you can help me).

Basically, I'd like a button doing the following:

  1. Open a dialog to let me select a folder.
  2. Search all image files (*.jpg, *.jpeg, .*tif, *.bmp) inside that folder and subfolders.
  3. Check if a image height is over 1080 pixels then:
    a) If the image length is less than 1920 pixels just convert the image into .jpg 100% quality (if already jpg do nothing)
    b) If the image length is more than 1920 pixels, convert the image into 1920x1080 .jpg leaving the quality untouched.
  4. Repeat for all images.

The important thing is that everytime I'd need not to create a second image, but replace the original one. Maybe this can be done in three passages: 1) Save with another name - 2) Delete the original file - 3) Rename the new file as the old one.

Thank you!

(Edit: Per tbone's suggestion below: Need a script/button to batch resize/convert images based on height )

This is way beyond the scope of SelectEx, it may be part of the solution, but I guess you'd be better of trying to get help in the general section and/or learning to write some code yourself in the long run.
I can imagine that using a clever search/filter, combined with some manual actions could get you near as well, that's why I suggest looking for general hints on this.

2 Likes

I wanted to delete half of the files in a folder randomly (large folder > 1 million files). I created this button

SelectEx RANDOM FILES ITEMCOUNTPERC=50

but it didn't seem to work.

Then I realized it took a while to select it all. Great command!