Create folder.jpg on selected folders

Hello all,

Currently, I go into a folder, randomly select an image (or run tbone's SelectRandom script) and run this button:

Image CONVERT=jpg HERE AS=folder.jpg HEIGHT=512 WIDTH=512 PRESERVEASPECTRATIO REPLACE=always SetAttr ATTR=hs FILE=folder.jpg
Is there anyway to somewhat automate this? I was hoping to run the above code on selected folders instead of having to go into each folder (HUGE time saver).

Example:
The script goes into each selected folder, randomly selects an image, then does the above code. Instantly creating folder.jpg for each folder and hiding it. If I don't like the result of one of the folders, I can select that folder and run the script again. Hopefully, it would randomly pick a different image to work from.

@tbone. Maybe this could be part of your SelectRandom script? :slight_smile:

It's definitely possible for a script to do this. For each selected folder, the script could enumerate its files and pick a random image, then run the Image CONVERT and SetAttr commands on it.

I updated SelectRandom to allow "selecting" of items from an external folder, instead of the current filedisplay only.
The result can be put into tab/env variables now, watch the descriptions and example given. The changes done to SelectRandom should provide what is required to get a decent solution.

You need to turn your button into a script button which iterates over the selected folders, like so:

for (var iEnum = new Enumerator(data.func.sourcetab.selected_dirs); !iEnum.atEnd();){ var item = iEnum.item(); iEnum.moveNext(); DOpus.Output("Selected folder: " + item.realpath); }
Then call SelectRandom for each of the selected folders to get your image filename. What's left is to adjust your statements above to work around folder.jpg within the folders affected (add PATH argument).

Thank you, tbone, for the changes!

Sounds like between your changes to SelectRandom and what Leo linked to, this should be possible.

I'm sorry if I gave the impression that I can actually program. The most I can do is the basics with standard dopus commands :wink:

The sample you just gave and the new code variables you added are way over my head.

Anymore help from anyone would be greatly appreciated!

For managing folder images, you might find this script handy.
Manage folder and video thumbnails v0.4.3

It can:
[ul]
[li]Create thumbnails for all videos in a folder.[/li]
[li]Set a selected image as the folder.ext.[/li]
[li]Select find a random image in the folder and set it as the folder.ext.[/li][/ul]

Thanks, wowbagger.

When I configured it to not look into the 'thumbs' folder for an image, it works great!

I was able to also change it's size and set the hidden attribute at the same time:

SetFolderThumbnailToRandom Image FILE={filepath}/folder.jpg HEIGHT=512 WIDTH=512 PRESERVEASPECTRATIO REPLACE=always SetAttr ATTR=hs FILE={filepath}/folder.jpg
Question:
Is there a way to not modify the Date Modified time stamp of the folders?

Thanks :thumbsup:

I added options to set the thumbnail to hidden and one to resize the thumbnail. Resizing is not working, not sure why.
You can see changes here Manage folder and video thumbnails v0.5.0. Its beta, so test. I will try figure out the image resizing later.

NTFS changes the folder modified datatime if any file inside it is modified. I'm there are ways around this (using powershell and prob others) but its not something I would recommend.

Thank you for the FlagThumbnailsAsHidden option. Works great. One less line of code in the button.

No need to keep updating this thread. I'll watch the other thread for when you manage to get resizing to work (I'm sure you'll get it) and I'll update in that thread. For now, I'll keep that line of code in my button.

Thank you kindly good sir, for this script and the added features :thumbsup:

I'm sorry, tbone. That you might of wasted your time making changes to your SelectRandom script to help me out. I'm sure they'll come in use for somebody down the road. :slight_smile: Thank you

Image resize is fixed.

Not wasted time ktb! o)

To give another hint on how to use SelectRandom, here is a demo-button that does what you initially requested. The beauty with this is in the flexibility (to me at least o). You can use any DO command on the result and you're not dependent on another addin and its features. I prefer modular concepts and this once fits DOs internal commands and how you'd put them together to get something new.

Just don't get me wrong, I understand your point of view (give me a one-liner button! o) and also appreciate wowbaggers work! o)

@script jscript

function OnClick(data){
	var cmd = data.func.command, tab = data.func.sourcetab;
	for (var iEnum = new Enumerator(tab.selected_dirs); !iEnum.atEnd(); iEnum.moveNext()){
		var folder = iEnum.item()
		cmd.RunCommand('SelectRandom PATH="'+folder.realpath+'" RECURSE FILES SETTABVAR="SRResult" name="\.jpg$"');
		var imagePath = tab.Vars.Get("SRResult");
		if (imagePath=="") continue;
		cmd.RunCommand('Image CONVERT=jpg AS=folder.jpg HEIGHT=512 WIDTH=512 '+
			'PRESERVEASPECTRATIO REPLACE=always FROM="'+imagePath+'" TO="'+folder.realpath+'"');
		cmd.RunCommand('SetAttr ATTR=hs FILE="'+folder.realpath+'\\folder.jpg"');
	}
}

Thanks, tbone!

It works fantastically.

Thank you both for all the time and effort you put forth in helping me with this project. I really do appreciate it.

By the way. Even those few lines of code, makes no sense to me. I could never write that up myself. You programmers just think on a whole different level than I do :wink:

@wowbagger. I'll keep a close eye on yours to see when you get the current bug fixed. I like and want to use it for the folders that have videos in them.

:thumbsup:

Hi tbone,

With the button that you posted above. Is there any way to set it to only pick from the first % of files or first xx number of files?

If xx is possible, and I set it to 50 but there are only 30 in the folder, what would happen? This is why I think % would be best. Example: set to only pick from the first 10% of the list and there are 100 files, it would pick 1 from the first 10.

So you want to pick the folder thumb for the selected folders, from the first xx% of files within any of these selected folders? Did I understand correctly? Why is that you want it to work like that? Is that performance related maybe or just because your first xx% of image files are always the nicest? o)

Correct. And I guess the sorting would be by name.

Not a performance thing at all. It runs really well. I love the script. Lots of times I'm finding a better picture is always in the beginning of the group. So I would like to make a few buttons.

  • One for picking from the entire group (the way it works now)
  • One that picks from 50% first half
  • One that picks from 25% first half
  • One that picks from 10% first half

Or something like that.

Just gives me a little more control if I know the content. Instead of having to repeating until I get one that I know is early in the naming convention. :slight_smile:

This should do, and let's you adjust the percentages. Consider removing the DOpus.Output() lines and the ECHO switch, if your dealing with a huge amount of files (output can slow things down). You also need to install the successor to the "SelectRandom" command, it's called "SelectEx" and features the random selection as well. Here the LINEAR mode is used though, which fetches a specific amount of images first and then lets the snippet work on the returned list to choose one random entry. o)

@script jscript var percent = 20; function OnClick(data){ var cmd = data.func.command, tab = data.func.sourcetab; //cmd.deselect = false; for (var iEnum = new Enumerator(tab.selected_dirs); !iEnum.atEnd(); iEnum.moveNext()){ var folder = iEnum.item() DOpus.Output("Choosing from these images.."); cmd.RunCommand('SelectEx LINEAR PATH="'+folder.realpath+'" ITEMCOUNTPERC='+percent+' RECURSE FILES SETVAR="SexRes" name="\.jpg$" ECHO'); var imagePathsStr = new String(tab.Vars.Get("SexRes")); if (imagePathsStr=="") continue; var imagePathsArr = imagePathsStr.split("\n"); var randomIndex = Math.floor(Math.random() * imagePathsArr.length); DOpus.Output("Chosen image: " + imagePathsArr[randomIndex]); cmd.RunCommand('Image CONVERT=jpg AS=folder.jpg HEIGHT=512 WIDTH=512 '+ 'PRESERVEASPECTRATIO REPLACE=always FROM="'+imagePathsArr[randomIndex]+'" TO="'+folder.realpath+'"'); cmd.RunCommand('SetAttr ATTR=hs FILE="'+folder.realpath+'\\folder.jpg"'); } }

That works fantastically. Thank you very much, tbone!

:thumbsup:

Thanks for letting me know, a happy feedback is always appreciated! o)

Do you need Opus 11 for scripts to work?

Sorry skribb, I didn't realize you were on v10 in the other thread. Yes, you do need v11.