Execute DOPUS command on specific folder open and then revert

I feel like I've seen this done before but can't seen to find anything with the search function here.

What I want to do is simple, run a DOPUS command (or a few of them) to format a folder and then revert those changes after I leave the folder. The reason I need a command to do this instead of simply changing the folder format it because these commands are global. Specifically, Set THUMBNAILLABELS and Set ICONMODESORTHEADER. For my family pictures folder I do not need to see the thumbnail labels but for my work photos I do need the labels. Likewise, I need the sort header for a majority of my folders but I do not need it when looking through categorized Movies.

One last thing related to the above. Is it possible to do the same as above with thumbnail aspect ratio? I have photo albums that have a portrait aspect ratio and it would be amazing if I could get they displayed correctly.

Thanks as always!

You could use a script to change and/or revert the settings based on the folder you're in, or when changing folders generally, or activating different tabs, etc.

A simple script that runs a command after every folder change can be found here:

Thanks Leo, that will help. Is there anyway to get intellisense for directory opus functions?

Also, is it possible to change thumbnail aspect ratio via script as well?

Alright so this is the code I have so far:

// Reset folder format on every directory change

// Initilize script
function OnInit(initData)
{
	initData.name = "Video Folder Format";
	initData.version = "0.1";
	initData.copyright = "(c) 2019 Evernessince";
	initData.desc = "Formats your video folder";
	initData.default_enable = true;
	initData.min_version = "12.0";
}

// Apply changes to select folders
function OnAfterFolderChange(data)
{
	if(data.tab.path = "F:\Video Series") {
		var cmd = DOpus.Create.Command;
		cmd.RunCommand("Set ICONMODESORTHEADER=off");
	}
	return false;
}

I believe something is wrong with my data.tab.path object though as it isn't applying the command when I change to the specified folder. Also, this function should run on every folder change correct? Is there anyway to get it to only run on a specific folder?

Use DOpus.Output(data.tab.path) to see what the path you're comparing against is. That should let you work out why it isn't working. You can see the output via Tools > Script Log.

Looking at your script again, it's also failing because == or === are the equality-comparison operators in JScript. = is the assignment operator. So you aren't actually comparing data.tab.path to anything; you're trying to assign a value to it.

Change that line to if(data.tab.path == "F:\Video Series") {

Thanks Leo.

I made the changes

// Reset folder format on every directory change

// Initilize script
function OnInit(initData)
{
	initData.name = "Video Folder Format";
	initData.version = "0.1";
	initData.copyright = "(c) 2019 Evernessince";
	initData.desc = "Formats your video folder";
	initData.default_enable = true;
	initData.min_version = "12.0";
}

// Apply changes to select folders
function OnAfterFolderChange(data)
{
  DOpus.Output(data.tab.path);
  var TargetPath = "F:\Video Series";
	if(data.tab.path == TargetPath) {
		var cmd = DOpus.Create.Command;
		cmd.RunCommand("Set ICONMODESORTHEADER=off");
	}
	return false;
}

The folder name being output matches the folder name I'm trying to compare it to

Untitled

But it's still not running the DOPUS command.

You probably need to use the cmd.SetSourceTab() method to target it at the correct tab. Add this line before the RunCommand:

cmd.SetSourceTab(data.tab);

You may also need to coerce the data.tab.path property to a string in order to compare it like that. Maybe try if (String(data.tab.path) == TargetPath).

// Reset folder format on every directory change

// Initilize script
function OnInit(initData)
{
	initData.name = "Video Folder Format";
	initData.version = "0.1";
	initData.copyright = "(c) 2019 Evernessince";
	initData.desc = "Formats your video folder";
	initData.default_enable = true;
	initData.min_version = "12.0";
}

// Apply changes to select folders
function OnAfterFolderChange(data)
{
  DOpus.Output(data.tab.path);
  var TargetPath = "F:\Video Series";
	if(String(data.tab.path) == TargetPath) {
		var cmd = DOpus.Create.Command;
		cmd.SetSourceTab(data.tab);
		cmd.RunCommand("Set ICONMODESORTHEADER=off");
	}
	return false;
}

Thanks for the reply Jon. I made the proposed changes but unfortunately it still isn't running the DOPUS command.

Oh, I just realised that backslashes need to be escaped in JScript. You'll need var TargetPath = "F:\\Video Series";.

1 Like

This worked perfectly. Thanks a ton Jon. With this as a template I should be able to do everything else I need.

1 Like

A quick closing question: Will this script affect the speed at which folders are opened? I'm just wondering as the event is triggered on every folder change. I'd wager that directory opus goes to the folder first and displays it's content before triggering the script correct?

Just running the script and comparing paths should not have any noticeable impact, unless you measured things down to a millisecond level.

If the script runs a command which takes time then it could be an issue, of course. But I would only worry about that if things seem slow.

1 Like

I did notice a bit more delay when opening folders so I decided to test this out.

Using a 960 FPS camera and a 144 Hz monitor I started all my test runs in the same folder and clicked on the same folder. The MS values measure from the frame the click is registered on the screen to the 1st frame showing the contents of the folder. The test folder has 1,965 files in it. This folder resides on a HDD.

With script

run 1 - 102 frames
run 2 - 134 frames
run 3 - 96 frames
run 4 - 142 frames
run 5 - 120 frames

average time in ms - 123.55ms

average = (sum of all the runs / number of runs)*1.04

without script

run 1 - 85 frames
run 2 - 51 frames
run 3 - 133 frames
run 4 - 116 frames

average time in ms - 101.25ms

I did additional runs on my SSD with the C:\Program Files (x86) this time, just to ensure the HDD itself wasn't the bottleneck.

with script

run 1 - 98 frames
run 2 - 113 frames
run 3 - 142 frames

average - 122.37ms

without script

run 1 - 107 frames
run 2 - 83 frames
run 3 - 104 frames

average - 101.92ms

It's pretty consistent across SSDs and HDDs. On average the script caused an additional delay of 21.375ms.

Test system specs in case you want to reproduce:

Ryzen 3700X
X570 Taichi
16GB DDR4 3600 CL15 (2x8GB)
Samsung 750 evo 500GB (for SSD test)
WD Gold 12TB (for HDD test)
EVGA 1080 Ti Black

I don't think most people would notice the difference but it is there. Is the added latency because DOPUS must run the script to completion before displaying the folder's contents?

It takes a non-zero amount of time to do anything. The with/without times overlap and vary so much that I'd say most of it is within margin of error and the actual differences are very small; tens of milliseconds.

I think this chart is a good representation. Might be better if I did more w/o script as the sample size is a bit small and the points appear to be more spread out. Either that spread w/o the script is wider because I didn't take enough samples or because the script is adding a fixed amount of processing time to the "with script" points, bringing them all closer together.

In any case I think I've spent far too much time on this lol. I appreciate all the help Leo.

So, the overhead across 1000 directory changes will be 20 seconds?

It wouldn't be the first time I wasted more time benchmarking something than I could ever possibly save by optimizing it...

Correct. Unfortunately the script is so simple at this point that I don't think there is much optimization I can do. I would love it if I could assign scripts or internal functions to folders, then there would be no need to run a script on every folder.

I think you've spent more time worrying about it than you'll ever spend waiting on the scripts. :slight_smile: If you ignore the anomalously small ~50 frames value, the difference between the two groups on your graph is minuscule in terms of actual time (especially as a percentage of how long the operations take overall), and not something a human being would ever notice. The two ranges overlap hugely as well.

Use a script if it's useful. Don't use one if it isn't. But don't worry about it.