change case of selection
Hello!
A lot of times I have to change case of some part of my text to titlecase. So I've decided that it would be easier to write short script to do it automatically.
I've came with something like below.Basically after selecting part of text you want to change to title case you launch the script and it's done.
What do you think? It works for me, but maybe it could be better. Thanks in advance!
//variable made of selected text
var selectedWord = app.selection[0].contents;
//changing case of selection
var changeCase = app.selection[0].changecase (ChangecaseMode.titlecase);
//once more reading selection into variable
var changedWord = app.selection[0].contents;
//'find/change'
//clearing previous settings
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
//setting 'find' window
app.findGrepPreferences.findWhat = selectedWord;
app.findGrepPreferences.appliedParagraphStyle = 'BODY';
//setting 'change' window
app.changeGrepPreferences.changeTo= changedWord;
//undoing previous changes, just for keeping the order
var undoingChanges = document.undo();
//launching function
app.activeDocument.changeGrep();
// clearing previous settings
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
