Copy link to clipboard
Copied
Hello.
I think the title is clear enough. Well, a short explanation doesn't bother. 🙂
I'm looking for a way to take my first step in this project and create a "connection" between my InDesign document and a text file on my desktop. This text file is intended to serve as a source for extracting keywords from some book documents.
I didn´t found helpful threds in this forum. If one knows one, just send me the link please. 😉 Or a particular answer in this thread. Thanks!
This script searches for the individual words and exports the findings in a separate text file:
var txtsrc=File("/path/to/your/words.txt");
txtSrc.open("r");
var words = txtSrc.read().split(",");
var result = [];
for(var i = 0; i<words.length; i++) {
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = words[i];
try { result.push(app.activeDocument.findGrep()[0].contents) } catch(e) { };
}
var txtDest = new File("/path/to/your/result.txt");
txtDest.
...
Copy link to clipboard
Copied
This script searches for the individual words and exports the findings in a separate text file:
var txtsrc=File("/path/to/your/words.txt");
txtSrc.open("r");
var words = txtSrc.read().split(",");
var result = [];
for(var i = 0; i<words.length; i++) {
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = words[i];
try { result.push(app.activeDocument.findGrep()[0].contents) } catch(e) { };
}
var txtDest = new File("/path/to/your/result.txt");
txtDest.encoding = "UTF-8";
txtDest.open("w");
txtDest.write(result);
txtDest.close();
alert("Search result:\n" + result.length + "/" + words.length + " words found.\n\nSearch result exported to:\n" + txtDest);
Example:
Searching a document with this content
via words.txt containing
delta,test,kappa,phi,alpha,hello,world
will result in a result.txt containing
delta,kappa,phi,alpha
I hope, this script is a good start for your needs.
Copy link to clipboard
Copied
After a quick look it seems pretty helpful, thanks! 🙂
Copy link to clipboard
Copied
Nice one, @GNDGN. Just one comment: you need to reset the search options only once, so it's more efficient to take the line
app.findGrepPreferences = app.changeGrepPreferences = null;
out of the for-loop. Also, since you're not changing anything there's no need to reset the changeTo preferences, but that's a minor point.
P.
Copy link to clipboard
Copied
Hi all,
For those wondering how to also retrieve page numbers, you can use IndexMatic and submit your word list as a Query List (just need to replace commas by new lines). Here is a quick overview.
Step 1 — Load your List.
Go into Finder > Search Mode:Query List and click the ⇧ button to load your list.
Note. — You could technically keep the comma-separated list by using a ~format directive but it's a little more complicated.
Step 2 (optional) — Decide whether you Keep Zero-Frequency Terms.
If desired, in Output > Frequency, set Min to 0 (so not found items will be reported in the index.)
Step 3 (optional) — Run a Hits Report.
To get a preview, click the [Hits] button. (The console then reports actually found entries.)
Step 4 — Build the Index in Text Mode.
Having selected Output > Destination > Format: Text File, just click the button Index (TXT).
Tip: As long as you have less than 50 terms to report, IndexMatic TRY will do the job for free 😉
Best,
Marc