CreativePro Forum
Join our community of graphic designers, publishers, and production artists from around the world. Our members-only forum is a great place to discuss challenges and find solutions!
- You must be logged in to reply to this topic.Login
Script to print Found strings on an InDesign page
Tagged: printing in InDesign, printing with Find, scripts
- This topic has 7 replies, 2 voices, and was last updated 8 years, 9 months ago by
Kai Rübsamen.
-
AuthorPosts
-
-
March 17, 2017 at 6:14 am #92915
Tim Guymon
MemberI do typesetting for a religious journal, and I need to provide lists at the end of articles showing the scriptural references and the pages they appear on (or the footnote numbers).
I have written a script that will find the scripture references, but I’m stymied at getting InDesign to print something from the found strings. Ideally the list would be on a separate document (a text file), but I read somewhere that Javascript, for security reasons, will not write to an outside file. Okay, so let it add to the last page in InDesign–but I don’t know the code to make it spit it out.
Furthermore, I’m not sure of the logic of my procedure–I have an array of all the canonical books (Matthew, Mark, Luke, etc.) and a GREP expression that will pick up the references (5:48-50), and as a test, it successfully highlights all the references in the article–but is there a code that, inserted after the “Find” command, will print the product ($1)? So far I can get it only to print, literally, “$1” if with quotation marks; nothing if without.
Can anyone help, please? -
March 17, 2017 at 6:48 am #92916
Kai Rübsamen
MemberHi Tim,
you can store your found, e.g. “myDoc.findGrep()”. You will get an array of paragraphs, words or other things. Later you can put the “.contents” of those objects together, insert a page at the end, create a textframe with the proper margins and insert your stored contents. To write a .txt with your found on the desktop would also be possible.
Kai
-
March 17, 2017 at 12:29 pm #92920
Tim Guymon
MemberHi, Kai,
I appreciate from your reply that what I want is do-able; the problem is that I am a beginner. Although I have been shown enough to create a script that will find the strings I am looking for, I don’t know how to manipulate the “contents” of those findings other than to use “$1”–which doesn’t seem to work in the experiments I’ve tried. Can you show me a simple example of a script finding X string, then creating the textframe and writing that string on it? Thanks!
Regards,
Tim -
March 17, 2017 at 1:01 pm #92922
Kai Rübsamen
MemberPlease provide your script and a little example as idml-file.
Kai
-
March 17, 2017 at 1:55 pm #92924
Tim Guymon
MemberKai–
Here is the script:
var find = [
// Old Testament
“(Genesis|Gen.?)”,
“(Exodus|Ex.?)”,
“(Leviticus|Lev.?)”,
“(Numbers|Num.?)”,
“(Deuteronomy|Deut.?)”,
“(Joshua|Josh.?)”,
“(Judges|Jud.?)”,
“(Ruth)”,
“([12] (Samuel|Sam.?))”,
“([12] (Kings|Kgs.?)”,
“([12] (Chronicles|Chron.?)”,
“(Ezra)”,
“(Nehemiah|Neh.?)”,
“(Esther)”,
“(Job)”,
“(Psalms|Ps.?)”,
“(Proverbs|Prov.?)”,
“(Ecclesiastes|Eccl.?)”,
“(Song of Solomon)”,
“(Isaiah|Isa.?)”,
“(Jeremiah|Jer.?)”,
“(Lamentations|Lam.?)”,
“(Ezekiel|Ezek.?)”,
“(Daniel|Dan.?)”,
“(Hosea|Hos.?)”,
“(Joel)”,
“(Amos)”,
“(Obadiah)”,
“(Jonah)”,
“(Micah)”,
“(Nahum)”,
“(Habakkuk)”,
“(Zephaniah)”,
“(Haggai)”,
“(Zechariah)”,
“(Malachi)”,
// New Testament
“(Matthew|Matt.?)”,
“(Mark)”,
“(Luke)”,
“(John)”,
“(Acts)”,
“(Romans)”,
“([12] Corinthians)”,
“(Galatians)”,
“(Ephesians)”,
“(Phillippians)”,
“(Colossians)”,
“([12] Thessalonians)”,
“([12] Timothy)”,
“(Titus)”,
“(Philemon)”,
“(Hebrews)”,
“(Proverbs)”,
“(James)”,
“([12] Peter)”,
“([12] John)”,
“(Jude)”,
“(Revelations)”,
// Book of Mormon
“([1234] (Nephi|Ne?.?))”,
“(Jacob|Jac.?)”,
“(Enos)”,
“(Jarom|Jar.?)”,
“(Omni)”,
“(Words of Mormon)”,
“(Mosiah|Mos.?)”,
“(Alma)”,
“(Helaman|Hel.?)”,
“(Mormon|Mor.?)”,
“(Ether|Eth.?)”,
“(Moroni|Mor.?)”,
// Doctrine & Covenants
“(Doctrine and Covenants|D&C)”,
// Pearl of Great Price
“(Moses)”,
“(Abraham|Abr.?)”,
“(Joseph Smith–Matthew|JS–M)”,
“(Joseph Smith–History|JS–H)”,
“(Articles of Faith)”,
//Other books
“(Documentary History of the Church|DHC)”,
“(History of the Church|HC)”,
];
//var prt = new Array(100);
var ln = “”;
app.findChangeGrepOptions = null;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findChangeGrepOptions.includeFootnotes = true;
for (var i = 0; i < find.length; i++)
{
ln = “(” + find[i] + ” d{1,3}[:–]d{1,3}([;–]d{1,3})?(, d{1,3})?(; d{1,3})?([:?]d{1,3})?)”;
app.findGrepPreferences.findWhat = ln;
app.changeGrepPreferences.fillColor = ‘C=0 M=100 Y=0 K=0’; //red
app.changeGrepPreferences.changeTo = “$1”;
app.activeDocument.changeGrep();
// prt[i] = $1;
}
// for(var i = 0; i<find.length; i++)
// alert(prt[i]);and a sample of a file:
The collocation “refuse to be comforted,” as used here by Enoch, is abundantly attested throughout the Hebrew Bible. The Psalmist recalls, “In the day of my trouble I sought the Lord: my sore ran in the night, and ceased not: my soul refused to be comforted [m???nâ hinn???m napšî]” (Psalms 77:2 [MT 77:3]). Similarly, Jeremiah records the Babylonian destruction of Ramah in the tribal land of Benjamin, just north of Jerusalem at the time of the exile: “Thus saith the Lord; A voice was heard in Ramah, lamentation, and bitter weeping; Rahel [Rachel] weeping for her children refused to be comforted [m???nâ l?hinn???m] for her children, because they were not” (Jeremiah 31:15). Nearer the Noah story in Genesis, at the beginning of the Joseph cycle, we note Jacob’s making a similar declaration after his son Joseph’s apparent demise: “And all his sons and all his daughters rose up to comfort him [l?na??mô]; but he refused to be comforted [wa-y?m???n l?hitna??m]; and he said, For I will go down into the grave unto my son mourning. Thus his father wept for him” (Genesis 37:35).
In the context of the narrative, Enoch’s declaration “I will refuse to be comforted” clearly anticipates the formal etiology subsequently proffered in Genesis 5:29/Moses 8:9: “And he called his name Noah, saying: This [son] shall comfort us [Hebrew y?na??m?nû] concerning our work and toil of our hands, because of the ground which the Lord hath cursed” (see further below). Enoch’s “refus[al] to be comforted” thus frames Noah’s story in an entirely new way and helps us understand the “comfort” which Lamech foresees (and which the Lord shows Enoch) Noah will bring. Noah and his posterity — specifically his descendant Jesus Christ — will eventually bring “comfort” and “rest” to the earth in a manner that vastly transcends the idea that the patriarch Noah would merely give “comfort” as a winemaker (see below). Noah’s seed would include the Messiah, who would atone so that “all they that mourn mayThanks for your help!
Regards,
Tim -
March 17, 2017 at 2:41 pm #92925
Kai Rübsamen
MemberHi Tim,
here is your example. Realize that this is not the order by page!
var list = [ "(Genesis|Gen.?)", "(Psalms|Ps.?)", "(Jeremiah|Jer.?)", "(Moses)" ]; var curDoc = app.activeDocument, nList = list.length, curListItem, strToSearch, found, foundList = [], curFound; app.findGrepPreferences = app.changeGrepPreferences = null; app.findChangeGrepOptions.includeFootnotes = true; for (var i = 0; i < nList; i++) { curListItem = list[i]; strToSearch = "(" + curListItem + " d{1,3}[:–]d{1,3}([;–]d{1,3})?(, d{1,3})?(; d{1,3})?([:?]d{1,3})?)"; app.findGrepPreferences.findWhat = strToSearch; found = curDoc.findGrep(); if (found.length > 0) { for (var j = 0; j < found.length; j++) { curFound = found[j]; foundList.push(curFound.contents); } } } app.findGrepPreferences = app.changeGrepPreferences = null; alert(foundList); var tf = curDoc.textFrames.add({geometricBounds: [10, 10, 200, 200]}); tf.contents = foundList.join("\r");Kai
-
March 17, 2017 at 7:35 pm #92926
Tim Guymon
MemberKai–
Thank you very, very much! This is just what I needed! Is there any way I can send you some money for this?–I would like to; this is invaluable information!
One comment: I should have mentioned this, but the document itself is formatted, and each page has its own text frame. How would it work if the final two lines merely added foundlist to the current page?–I could then easily clip out the list and put it wherever I wanted.
Thanks again!
Regards,
Tim -
March 18, 2017 at 2:24 am #92927
Kai Rübsamen
MemberSending money is possible via PayPal :)
To your last question: I’m not sure, if I understand this correctly. Please sent me a testfile with 5 pages as idml to forumATruebiarts.de
Kai
-
-
AuthorPosts
- The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
