Page 1 of 1
Script to Capitalize Words' First Letters
Posted: 03 Jun 2020 07:07
by Jack99
Hi, I have just created a customized toolbar button, which executes the next renaming function:
rename s, " >."
I would like to extend its capabilities, starting by making it capitalizes words. But after reading the included help file,
I still didn't find the right way of doing that. It should perform the same renaming routine as when the predefined
"A* A*.aaa" function is invoked.
Thanks.
Re: Script to Capitalize Words' First Letters
Posted: 03 Jun 2020 07:14
by RalphM
Just use the command id for built in functions (#138 or #126, depending on which camel case you want).
Help/Show Command ID's in menu toggles the display of the id's.
Re: Script to Capitalize Words' First Letters
Posted: 03 Jun 2020 09:12
by Jack99
I'm being able to run one script at a time, but I can't make them run simultaneously. What I have tried:
rename s, " >."; ::#138;rename s, "A123/a123";
Expected result:
"The quick brown fox jumps over the lazy dog A123"
"The.Quick.Brown.Fox.Jumps.Over.The.Lazy.Dog.a123"
Similarly, when I try to combine commands into the "Rename Special > Search and Replace" function, they are executed
separately only (without quotes):
" >. "
"A123/a123 /c"
And the one that capitalizes first letters, which I don't know.

Re: Script to Capitalize Words' First Letters
Posted: 03 Jun 2020 09:27
by highend
rename s, " >."; #138; rename s, "A123/a123";
Works here. But the third command isn't even necessary. #138 will already "decapitalize" the extension.
And the one that capitalizes first letters, which I don't know.
That function (apart from the id) doesn't do that. You would need to script that.
Re: Script to Capitalize Words' First Letters
Posted: 03 Jun 2020 09:54
by Jack99
As you mentioned, after removing the "::", the command worked as expected.

But I kept the last command as well, since
that "A123" from the example isn't an extension, but a starting letter from a single word that might be already capitalized and I
need it as lower case.
Could the commands be combined as well, when using the "Rename Special > Search and Replace" function? At least the allowed commands to use with it, without having to create a specific script.
Re: Script to Capitalize Words' First Letters
Posted: 03 Jun 2020 10:04
by highend
No, you can't combine them via the context menu entry.
Re: Script to Capitalize Words' First Letters
Posted: 03 Jun 2020 10:27
by highend
To show you a way how things can be scripted...
Code: Select all
$from = " ";
$to = ".";
$exclude = "A123";
$sample = "The quick A123 brown fox jumps over the lazy dog";
$new = CapitalizeWords($sample, $exclude);
$new = replace($new, $from, $to);
// Rename item via "renameitem"
text $new;
// $exclusions must be separated by "|"
function CapitalizeWords($string, $exclusions) {
$string = recase($string, "camel");
foreach($item, $exclusions, "|", "e") {
if (strpos($string, $item, 0, 1) != -1) { $string = replace($string, $item, recase($item, "l")); }
}
return $string;
}
Re: Script to Capitalize Words' First Letters
Posted: 03 Jun 2020 10:50
by Jack99
OK, I will try that one later.
By the way, I just noticed that if the above script is put like this:
Code: Select all
rename s, " >."; rename s, "X264/x264"; #138;
The " rename s, X264/x264" part will have no effect at all. The only difference being the commands' order (#138 in the third place, instead the second one).
Thanks.
Re: Script to Capitalize Words' First Letters
Posted: 03 Jun 2020 10:52
by highend
The " rename s, X264/x264" part will have no effect at all.
Of course it has an effect, but the third command will negate it...
Re: Script to Capitalize Words' First Letters
Posted: 05 Jun 2020 22:02
by Jack99
You are right, the "#138" command will capitalize it again.
