Word has a nice feature that lets you select some text and press Shift+F3 to cycle between all the available capitalization modes: so you cycle through the options like this:
cycle > Cycle > CYCLE > cycle
just by pressing Shift+F3.
What’s also nice in Word is that it is not necessary to select the whole word – it’s enough to place the cursor somewhere inside the word and press F3 and the capitalization of the whole word is changed.
This all may sound rather minor, but in practice, especially if editing a long piece, it streamlines a repetitive process.
InDesign also has capitalization options: select some text, go to the Type menu, point to Change Case, and there you’ll see the four options InDesign provides: UPPERCASE, lowercase, Title Case, and Sentence case (sentence case just capitalizes the first word in a sentence).
What InDesign lacks, though, is any way of cycling through those cases. Of course it would be possible to assign four different keyboard shortcuts to the four different options, but who wants to remember 4 separate key combinations for something so trivial? A single keyboard shortcut the cycles through all the possible options is much more convenient.
So the following script attempt to mimick Word’s “cycle case” functionality. To use, select some text, or place your cursor inside a word, and run the script. Got the capitalization you’re looking for? Good. If not, run the script again. To truly emulate Word, assign a keyboard shortcut to the script, and you’ve got yourself an InDesign Case Cycle script!
//BS"D //Cycle Case //An InDesign script (c) Ariel Walden, 2011; revised 2015 //Freebie script from www.Id-Extras.com try{ mySelection = app.selection[0]; // If selection is insertionPoint, get word associated with that insertionPoint if (mySelection instanceof InsertionPoint){ // Simple case: insertionPoint is in middle of word if (mySelection.words[0].isValid) mySelection = mySelection.words[0]; else{ myIndex = mySelection.index; // More complicated: insertionPoint is to the left of a word if (mySelection.parent.insertionPoints[myIndex+1].words[0].isValid) mySelection = mySelection.parent.insertionPoints[myIndex+1].words[0]; else { // insertionPoint is to the right of a word mySelection = mySelection.parent.insertionPoints[myIndex-1].words[0]; } } } myText = mySelection.contents; switch (myText){ // If uppercase, change to lowercase case myText.toUpperCase(): mySelection.changecase(ChangecaseMode.LOWERCASE); break; // if lowercase, change to sentencecase case myText.toLowerCase(): mySelection.changecase(ChangecaseMode.SENTENCECASE); // sometimes, switching to sentencecase achieves nothing (e.g., if selected word is in middle of sentence), so only break if something has changed if (mySelection.contents != myText) break; // no direct javascript way to check for sentencecase, so divide string into two and check. Also, switch to titlecase if we're still in lowercase in middle of sentence case (myText[0].toUpperCase() + myText.substr(1).toLowerCase() || myText.toLowerCase()): // if sentencecase change to titlecase mySelection.changecase(ChangecaseMode.TITLECASE); // but sometimes, sentencecase and titlecase are identical. If that is not the case, we're okay, since we've changed something, so the cycling will continue, so break if (mySelection.contents != myText) break; // ... if we're here, it means that the current text wasn't any predefined mode (e.g. "aBcdE"), or that changing to titlecase from sentencecase achieved nothing, so start the cycle by switch to uppercase default: mySelection.changecase(ChangecaseMode.UPPERCASE); } } catch(_){}
Incidentally, this script is a revision of a popular little script I published a few years ago. In this revised version, InDesign’s Sentence Case option has been added to the script as well.
PS In fact, although the idea behind the script is trivial, the implementation is a little involved, as you can see. There are 2 main difficulties: (1) To get a handle on the word that is adjacent to the cursor, if no text is selected, and (2) to make sure that every time the script is run, something happens to the capitalization, because otherwise the script could get stuck.
For instance, if there is only one word selected, there may be no difference between InDesign’s sentence case and InDesign’s title case. And since the script goes from sentence case to title case, nothing will actually happen, meaning that the script would get stuck on sentence case. Hence the rather convoluted switch statement above!
Well, I hope this little script is useful for you. If you use it, please leave some feedback below! Thanks.
James Rodriguez
March 31, 2022 10:46 pmHi.
I installed old version and shows me the interface, but does not work when i clic some option.
Now, I create a .jsx file from notepad with that code you gave, and works every time I clic “run” on scripts panel, but never with SHIFT+F3.
What I’m doing wrong?
My InDesign is version 16.0 in spanish…. I have to do something more to use it the right way?
Thanks a lot.
Ariel
April 4, 2022 6:50 pmTo get the F3 thing to work, you’ll need to assign that shortcut to this script yourself, in InDesign’s shortcut editor (Edit > Keyboard Shortcuts…)
Tamara
July 22, 2021 4:27 pmHi! Sorry to bother, but how could i use the script? I don’t know what to to with the code, all my scripts are JSX files
Ariel
August 5, 2021 10:30 amHi Tamara,
Use this .jsxbin script file in exactly the same way you would use a regular .jsx file.
Ariel
Shmuel Gerber
December 9, 2020 2:03 amThank you!
Rado
November 26, 2020 5:30 pmHello Ariel,
thank you for this script, works perfectly in my Indesign CC 2021.
Many thanks,
Rado
Ariel
November 26, 2020 6:35 pmThanks Rado, glad to hear it!