Extract words with specific style applied
Hi,
Is possible extract words with a specific character style applied to other indesign document or a txt file using a script?
Thank you in advance!
Hi,
Is possible extract words with a specific character style applied to other indesign document or a txt file using a script?
Thank you in advance!
Try this:
var doc = app.activeDocument;
var list = [];
//~ var sel = app.selection[0].parentStory;
app.findGrepPreferences = app.changeGrepPreferences = app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findGrepPreferences.appliedCharacterStyle = doc.characterStyles.itemByName("test");
//~ var found = sel.findGrep();
var found = doc.findGrep();
app.findGrepPreferences = app.changeGrepPreferences = app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
for (var i=0; i<found.length; i++) {
list.push(found.contents);
}
//~ alert(list.join("\r"));
var myFile = new File(Folder.desktop + "/" + app.activeDocument.name.replace(/\.indd$/i, ".txt"));
if (File.fs == "Windows")
var listFile = myFile.saveDlg("Save list", "Plain text file: *.txt" );
else
listFile = myFile.saveDlg("Save list");
if (listFile != null)
{
if (listFile.open("w"))
{
listFile.encoding = "utf8"; //ENCONDING
listFile.write(list.join("\r") + "\r"); //WRITE THE ARRAY TO TXT FILE
listFile.close(); //CLOSE TXT FILE
listFile.execute(); //OPEN TXT FILE
}
}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.