GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Uppercase Range

Overview

This preset asks for a start position and length, then converts the specified region of the file name into upper case.

The Rename dialog already has built-in options to modify the case of the whole filename, or every word, and similar, if you need that instead. This preset is only useful if you want to uppercase a specific part of the filenames by position and length.

Two extra fields are added to the Rename dialog so you can specify the position and length to uppercase:

2020-04-02 00-20-36 Clipboard Image

The Uppercase Position value starts at zero. If you wanted to uppercase the first five characters, you would set Position = 0 and Length = 5.

The Uppercase Length value can be longer than the names (it's 999 by default) if you want to uppercase everything from the position to the end of the names.

The file extension is always left as-is, but you can use the Modify Capitalization option in the Rename dialog to affect that at the same time if you wish.

Preset / Download

Here's the rename preset:

Script Code

Here's the full script code inside the preset, for reference:

function OnGetNewName(getNewNameData)
{
	var name = getNewNameData.newname_stem_m;
	var ext = getNewNameData.newname_ext_m;

	var pos = getNewNameData.custom.pos;
	var len = getNewNameData.custom.len;

	if (name.length > pos)
	{
		var A = name.substr(0,pos);
		var B = name.substr(pos,len);
		var C = name.substr(pos+len);

		name = A + B.toUpperCase() + C;
	}

	return name + ext;
}

function OnGetCustomFields(getFieldData)
{
	getFieldData.fields.pos = 0;
	getFieldData.fields.len = 999;

	getFieldData.field_labels("pos") = "Uppercase Position";
	getFieldData.field_labels("len") = "Uppercase Length";
}
1 Like

Hi Leo I Import the .orp file in my rename presets. Then Create a toolbar button with this code:

@nodeselect
Rename PRESET="Uppercase Range" 

Then Select a file & Click on the toolbar button but nothing happens

That would run the preset as-is without opening the rename dialog. Add the ADVANCED argument if you want the dialog to open at the same time as specifying a preset to use.

1 Like

After add the ADVANCED argument it's work.
It's work via Rename dialog box, but That would be better If the script can produce a little dialog box it self where we can input the Uppercase Position & Uppercase Length

That isn't what it's for. If you want that you'll have to write it yourself.

2 Likes

Thanks for the nice script Leo