Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
7

External, comma-separated text file as search base

Participant ,
Dec 12, 2023 Dec 12, 2023

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!

TOPICS
Scripting
681
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Dec 12, 2023 Dec 12, 2023

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.
...
Translate
Participant ,
Dec 12, 2023 Dec 12, 2023

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

1.PNG

 

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.

____________________
Robotic Process Automation in Desktop Publishing (Book): https://doi.org/10.1007/978-3-658-39375-5
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 12, 2023 Dec 12, 2023

After a quick look it seems pretty helpful, thanks! 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 12, 2023 Dec 12, 2023

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 13, 2023 Dec 13, 2023
LATEST

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.

 

Wordlist01.png

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.)

 

Wordlist02.png

 

Step 3 (optional) — Run a Hits Report.

To get a preview, click the [Hits] button. (The console then reports actually found entries.)

 

Wordlist03.png

 

Step 4 — Build the Index in Text Mode.

Having selected Output > Destination > Format: Text File, just click the button Index (TXT).

 

Wordlist04.png

 

Tip: As long as you have less than 50 terms to report, IndexMatic TRY will do the job for free 😉

 

Best,

Marc

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines