Copy link to clipboard
Copied
I want change each word's first letter to capital.
Help me~
Thank you very much!
-----------------------------------------------------Below,there is already script.------------------------------------------------------------
//BS”D
//ToggleCase
//An InDesign CS4 script (c) Ariel Walden, 2011
//Freebie script from http://www.FreelanceBookDesign.com
try{
mySelection = app.selection[0];
if (mySelection instanceof InsertionPoint){
if(mySelection.words[0].isValid) mySelection = mySelection.words[0];
else{
myIndex = mySelection.index;
if (myIndex < mySelection.parent.insertionPoints[-1].index && mySelection.parent.insertionPoints[myIndex+1].words[0].isValid) mySelection = mySelection.parent.insertionPoints[myIndex+1].words[0];
else {
mySelection = mySelection.parent.insertionPoints[myIndex-1].words[0];
}
}
}
myText = mySelection.contents;
if (myText != myText.toUpperCase() && myText != myText.toLowerCase()) mySelection.changecase(ChangecaseMode.UPPERCASE);
if (myText == myText.toUpperCase()) mySelection.changecase(ChangecaseMode.LOWERCASE);
if (myText == myText.toLowerCase()) mySelection.changecase(ChangecaseMode.SENTENCECASE);
if (myText == myText.toSentenceCase()) mySelection.changecase(ChangecaseMode.TITLECASE);
if (myText == mySelection.contents) mySelection.changecase(ChangecaseMode.UPPERCASE); //necessary because if lowercase letter in middle of word selected, changing to titlecase does nothing.
}
catch(f){}
Copy link to clipboard
Copied
You want Title Case? So just run the script again!
The point of the script is to cycle (not toggle!) the current selection
through three capitalization modes -- it makes it easy to switch the
select word to all caps, or title case, or lower case, like Word's
built-in function. The script works best if you assign a keyboard
shortcut to it -- just select your text, and keep hitting the shortcut
until you get the capitalization you want.
Hope that explanation helps. What I'm saying is that what you appear to
be asking is already the way the script works!
Copy link to clipboard
Copied
Hold on! I just noticied that what you've posted is modified version of my script -- and, almost inevitably -- the modification broke it! To make it work as originally intended -- delete the line with the SENTENCE CASE option, so the original script should look like this:
//BS"D
//ToggleCase
//An InDesign CS4 script (c) Ariel Walden, 2011
//Freebie script from www.Id-Extras.com
try{
mySelection = app.selection[0];
if (mySelection instanceof InsertionPoint){
if(mySelection.words[0].isValid) mySelection = mySelection.words[0];
else{
myIndex = mySelection.index;
if (mySelection.parent.insertionPoints[myIndex+1].words[0].isValid) mySelection = mySelection.parent.insertionPoints[myIndex+1].words[0];
else {
mySelection = mySelection.parent.insertionPoints[myIndex-1].words[0];
}
}
}
myText = mySelection.contents;
if (myText != myText.toUpperCase() && myText != myText.toLowerCase()) mySelection.changecase(ChangecaseMode.UPPERCASE);
if (myText == myText.toUpperCase()) mySelection.changecase(ChangecaseMode.LOWERCASE);
if (myText == myText.toLowerCase()) mySelection.changecase(ChangecaseMode.TITLECASE);
}
catch(f){}
Copy link to clipboard
Copied
I've updated the original script, so it now includes SentenceCase: