Hi there!
I'm very newbie to scripting and I have the following script which finds "AllCaps" format text and change it to real uppercase. I'm working with ID CS 6 on Windows XP.
The script works on a single document if there's one open, otherwise it asks for a folder and process all the INDD files in that folder.
This is what I have:
if(app.documents.length != 0){ processDocument(app.activeDocument); alert("Done!"); } else { _folder = Folder('~/Desktop').selectDlg("Select folder"); if(_folder == null) exit(); _files = _folder.getFiles("*.indd"); if(_files.length == 0){ alert("No INDD files in the selected folder!"); } else { for (i=0; i<_files.length; i++){ app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT; _inddFile = _files[i] doc = app.open(_inddFile); app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL; processDocument(doc); app.activeDocument.close(SaveOptions.yes); } alert("Done!"); } } function processDocument(doc) { app.findGrepPreferences = app.changeGrepPreferences = null; app.findGrepPreferences.capitalization = Capitalization.allCaps; app.findGrepPreferences.appliedCharacterStyle = 'Red'; var _results = doc.findGrep(); app.findGrepPreferences = app.changeGrepPreferences = null; _length = _results.length; for (i=0; i<_length; i++) { _results[i].texts[0].changecase(ChangecaseMode.uppercase); _results[i].texts[0].capitalization = Capitalization.normal; _results[i].texts[0].appliedCharacterStyle = 'Blue'; } }
The script works well on a single document, but for some reason it doesn't work on multiple documents. I'm trying the script on 4 files with this content (colors are added to the text only to help verify the results):
Every time only the first or the first two documents are processed correctly, the others are not processed at all. But I'm getting no error message. Where's the problem?
Any help would be greatly appreciated!
Luca