Highlighted

Script to sort list of Bible references in Bible order

Explorer ,
Apr 23, 2020

Copy link to clipboard

Copied

Hello,

Is anyone aware of a script that will sort a list of Bible references into the order the books appear in the Bible (i.e., beginning with Genesis)? Each reference is in its own paragraph, beginning with the name of the book.

If there isn’t a specific script for that, a script where you can map a list to a sort number and do the sort that way would also be great (e.g., Genesis = 1, Exodus = 2, and so on).

Thank you.

Correct answer by DubSavage | Community Beginner

This is funny. I was just working on that solution.
It might be clunky and have potential issues but this is it so far:


Application.prototype.main = function() {
var theParagraphs = app.selection[0].paragraphs.everyItem().getElements();
 
//Add indexOf to prototype Array
Array.prototype.indexOf = function (elem, fromIndex){  
fromIndex = Number(fromIndex) || 0;  
var len = this.length;  
if (fromIndex < 0){  
fromIndex += len;  
}  
for(var i=fromIndex;i<this.length;i++){  
if(this[i] == elem){  
return i;  
}  
}  
return -1;  
}  
 
 
var bookList = ["Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy", "Joshua", "Judges", "Ruth", "1 Samuel", "2 Samuel", "1 Kings", "2 Kings", "1 Chronicles", "2 Chronicles", "Ezra", "Nehemiah", "Esther", "Job", "Psalms", "Proverbs", "Ecclesiastes", "Song of Solomon", "Isaiah", "Jeremiah", "Lamentations", "Ezekiel", "Daniel", "Hosea", "Joel", "Amos", "Obadiah", "Jonah", "Micah", "Nahum", "Habakkuk", "Zephaniah", "Haggai", "Zechariah", "Malachi", "Tobit", "Judith", "Ecclesiasticus (Sirach)", "Matthew", "Mark", "Luke", "John", "Acts", "Romans", "1 Corinthians", "2 Corinthians", "Galatians", "Ephesians", "Philippians", "Colossians", "1 Thessalonians", "2 Thessalonians", "1 Timothy", "2 Timothy", "Titus", "Philemon", "Hebrews", "James", "1 Peter", "2 Peter", "1 John", "2 John", "3 John", "Jude", "Revelation"];
 
var newList = [];
var bookNumber, bookName;
 
 
 
for (var i = 0; i < theParagraphs.length; i++) {
newList.push(theParagraphs[i].contents);
}
 
//add double digit sorting numbers
for (var i = 0; i < newList.length; i++) {
bookName = newList[i].split(" ")[0];
if (bookName == "1"||bookName == "2"||bookName == "3") {
bookName = newList[i].split(" ")[0] + " " + newList[i].split(" ")[1];
}
 
if (bookList.indexOf(bookName)<9) {
bookNumber = "0" +(bookList.indexOf(bookName)+1) + "_";
}
else{
bookNumber = (bookList.indexOf(bookName)+1) + "_";
}
newList[i] = bookNumber + newList[i];
}
 
//sort list
newList = newList.sort();
 
 
//this part removes the sorting-number
for (var i = 0; i < newList.length; i++) {
newList[i] = newList[i].replace(/^\d+_/g, "");
}
 
//paragraphs contents updated
for (var i = 0; i < theParagraphs.length; i++) {
theParagraphs[i].contents = newList[i];
}
 
 
}
 
app.doScript('app.main();',ScriptLanguage.JAVASCRIPT,undefined,UndoModes.ENTIRE_SCRIPT, undefined);



 

 

edit: added ^ to grep replace

TOPICS
Scripting

Views

1.3K

Likes

Translate

Translate

Report

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

Script to sort list of Bible references in Bible order

Explorer ,
Apr 23, 2020

Copy link to clipboard

Copied

Hello,

Is anyone aware of a script that will sort a list of Bible references into the order the books appear in the Bible (i.e., beginning with Genesis)? Each reference is in its own paragraph, beginning with the name of the book.

If there isn’t a specific script for that, a script where you can map a list to a sort number and do the sort that way would also be great (e.g., Genesis = 1, Exodus = 2, and so on).

Thank you.

Correct answer by DubSavage | Community Beginner

This is funny. I was just working on that solution.
It might be clunky and have potential issues but this is it so far:


Application.prototype.main = function() {
var theParagraphs = app.selection[0].paragraphs.everyItem().getElements();
 
//Add indexOf to prototype Array
Array.prototype.indexOf = function (elem, fromIndex){  
fromIndex = Number(fromIndex) || 0;  
var len = this.length;  
if (fromIndex < 0){  
fromIndex += len;  
}  
for(var i=fromIndex;i<this.length;i++){  
if(this[i] == elem){  
return i;  
}  
}  
return -1;  
}  
 
 
var bookList = ["Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy", "Joshua", "Judges", "Ruth", "1 Samuel", "2 Samuel", "1 Kings", "2 Kings", "1 Chronicles", "2 Chronicles", "Ezra", "Nehemiah", "Esther", "Job", "Psalms", "Proverbs", "Ecclesiastes", "Song of Solomon", "Isaiah", "Jeremiah", "Lamentations", "Ezekiel", "Daniel", "Hosea", "Joel", "Amos", "Obadiah", "Jonah", "Micah", "Nahum", "Habakkuk", "Zephaniah", "Haggai", "Zechariah", "Malachi", "Tobit", "Judith", "Ecclesiasticus (Sirach)", "Matthew", "Mark", "Luke", "John", "Acts", "Romans", "1 Corinthians", "2 Corinthians", "Galatians", "Ephesians", "Philippians", "Colossians", "1 Thessalonians", "2 Thessalonians", "1 Timothy", "2 Timothy", "Titus", "Philemon", "Hebrews", "James", "1 Peter", "2 Peter", "1 John", "2 John", "3 John", "Jude", "Revelation"];
 
var newList = [];
var bookNumber, bookName;
 
 
 
for (var i = 0; i < theParagraphs.length; i++) {
newList.push(theParagraphs[i].contents);
}
 
//add double digit sorting numbers
for (var i = 0; i < newList.length; i++) {
bookName = newList[i].split(" ")[0];
if (bookName == "1"||bookName == "2"||bookName == "3") {
bookName = newList[i].split(" ")[0] + " " + newList[i].split(" ")[1];
}
 
if (bookList.indexOf(bookName)<9) {
bookNumber = "0" +(bookList.indexOf(bookName)+1) + "_";
}
else{
bookNumber = (bookList.indexOf(bookName)+1) + "_";
}
newList[i] = bookNumber + newList[i];
}
 
//sort list
newList = newList.sort();
 
 
//this part removes the sorting-number
for (var i = 0; i < newList.length; i++) {
newList[i] = newList[i].replace(/^\d+_/g, "");
}
 
//paragraphs contents updated
for (var i = 0; i < theParagraphs.length; i++) {
theParagraphs[i].contents = newList[i];
}
 
 
}
 
app.doScript('app.main();',ScriptLanguage.JAVASCRIPT,undefined,UndoModes.ENTIRE_SCRIPT, undefined);



 

 

edit: added ^ to grep replace

TOPICS
Scripting

Views

1.3K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 23, 2020 0
Adobe Community Professional ,
Apr 23, 2020

Copy link to clipboard

Copied

The pre-installed sample Sort Paragraphs script could probably be reconfigured to handle your use case, but it would take some lifting. In its base form it only sorts alphabetically, but I would start there. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 23, 2020 1
Most Valuable Participant ,
Apr 24, 2020

Copy link to clipboard

Copied

Can you post a snippet of sample text, as it appears now and how you'd like to have it sorted?

Would you run such a script on an entire document, or on a selected story or text frame, or only in a selected text?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 24, 2020 1
Explorer ,
Apr 24, 2020

Copy link to clipboard

Copied

Thank you for your response, _Jongware_. Optimally the script would run on selected text, but the target text could certainly be pulled out and run in a separate document or in a frame at the end of the document. The situation is scripture references in an index, typically about four hundred references. Here's a sample list sorted alphabetically, followed by the same list in Bible order, followed by a list of the Bible books with sort numbers.

 

List 1

1 Chronicles 1:13–16
1 Corinthians 11:17–34
1 Kings 14:21
1 Samuel 1:20
1 Thessalonians 4:16
1 Timothy 5:1–2
2 Chronicles 33:7
2 Corinthians 12:2
2 John verse 13
2 Kings 18:9–19:36
2 Samuel 1:24
Acts 1:15–20
Amos 5:18–27
Colossians 2:9
Daniel 10:5–7
Deuteronomy 1:37
Ecclesiastes 3:19
Ephesians 2:8–9
Exodus 12:1–28
Ezekiel 48:28
Ezra 2:63
Genesis 1
Hebrews 2:14–15
Hosea 1–3
Isaiah 10:24–34
James 1:6
Jeremiah 47:1, 2, 4
Job 19:25–27
Joel 2:1–11
John 1:14
Joshua 10
Jude verse 12
Judges 11:1–12:40
Lamentations 4:20
Leviticus 1–7
Luke 1:80
Mark 1:14, 15
Matthew 1:1–17
Micah 5:2
Nehemiah 7:65
Numbers 1:50, 53
Philemon verses 7, 20
Philippians 2:14–15
Psalms 109:6–8
Revelation 1:17
Romans 16:1
Ruth 4:11
Tobit 12:15
Zechariah 12:10

 

List 2

Genesis 1
Exodus 12:1–28
Leviticus 1–7
Numbers 1:50, 53
Deuteronomy 1:37
Joshua 10
Judges 11:1–12:40
Ruth 4:11
1 Samuel 1:20
2 Samuel 1:24
1 Kings 14:21
2 Kings 18:9–19:36
1 Chronicles 1:13–16
2 Chronicles 33:7
Ezra 2:63
Nehemiah 7:65
Job 19:25–27
Psalms 109:6–8
Ecclesiastes 3:19
Isaiah 10:24–34
Jeremiah 47:1, 2, 4
Lamentations 4:20
Ezekiel 48:28
Daniel 10:5–7
Hosea 1–3
Joel 2:1–11
Amos 5:18–27
Micah 5:2
Zechariah 12:10
Tobit 12:15
Matthew 1:1–17
Mark 1:14, 15
Luke 1:80
John 1:14
Acts 1:15–20
Romans 16:1
1 Corinthians 11:17–34
2 Corinthians 12:2
Ephesians 2:8–9
Philippians 2:14–15
Colossians 2:9
1 Thessalonians 4:16
1 Timothy 5:1–2
Philemon verses 7, 20
Hebrews 2:14–15
James 1:6
2 John verse 13
Jude verse 12
Revelation 1:17

 

List 3

1 Genesis
2 Exodus
3 Leviticus
4 Numbers
5 Deuteronomy
6 Joshua
7 Judges
8 Ruth
9 1 Samuel
10 2 Samuel
11 1 Kings
12 2 Kings
13 1 Chronicles
14 2 Chronicles
15 Ezra
16 Nehemiah
17 Esther
18 Job
19 Psalms
20 Proverbs
21 Ecclesiastes
22 Song of Solomon
23 Isaiah
24 Jeremiah
25 Lamentations
26 Ezekiel
27 Daniel
28 Hosea
29 Joel
30 Amos
31 Obadiah
32 Jonah
33 Micah
34 Nahum
35 Habakkuk
36 Zephaniah
37 Haggai
38 Zechariah
39 Malachi
40 Tobit
41 Judith
42 Ecclesiasticus (Sirach)
43 Matthew
44 Mark
45 Luke
46 John
47 Acts
48 Romans
49 1 Corinthians
50 2 Corinthians
51 Galatians
52 Ephesians
53 Philippians
54 Colossians
55 1 Thessalonians
56 2 Thessalonians
57 1 Timothy
58 2 Timothy
59 Titus
60 Philemon
61 Hebrews
62 James
63 1 Peter
64 2 Peter
65 1 John
66 2 John
67 3 John
68 Jude
69 Revelation

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 24, 2020 0
Explorer ,
May 04, 2020

Copy link to clipboard

Copied

Here are two short lists that might give a better idea. The first is in alphabetical order and the second is in the order the books appear in the Bible.

 

List 1
Deuteronomy 1:37
Exodus 12:1–28
Genesis 1
Joshua 10
Judges 11:1–12:40
Leviticus 1–7
Numbers 1:50, 53
Ruth 4:11

 

List 2
Genesis 1
Exodus 12:1–28
Leviticus 1–7
Numbers 1:50, 53
Deuteronomy 1:37
Joshua 10
Judges 11:1–12:40
Ruth 4:11

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 04, 2020 0
Adobe Community Professional ,
May 05, 2020

Copy link to clipboard

Copied

You'll certainly have to add some sort key because there is no way that the book order is predictable. A custom script with the book order hard coded is possible, but that's not straightforward.

One possibility is to add sort keys at the beginning of the entries. The keys can be numbers or letters. If you use numbers, use double-digit numbers if the number of books is larger than 9 (as you see I've no idea about the bible). You can leave the keys in place for future sorts if you want: apply a character style to them that hides them (apply 0.1 points type size, 1% horizontal scale, paper colour).

To sort the list you can use the script that Brian mentioned, but it is very slow. A quicker script is here:

https://creativepro.com/files/kahrel/indesign/sort.html

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 2
Community Beginner ,
May 05, 2020

Copy link to clipboard

Copied

This is funny. I was just working on that solution.
It might be clunky and have potential issues but this is it so far:


Application.prototype.main = function() {
var theParagraphs = app.selection[0].paragraphs.everyItem().getElements();
 
//Add indexOf to prototype Array
Array.prototype.indexOf = function (elem, fromIndex){  
fromIndex = Number(fromIndex) || 0;  
var len = this.length;  
if (fromIndex < 0){  
fromIndex += len;  
}  
for(var i=fromIndex;i<this.length;i++){  
if(this[i] == elem){  
return i;  
}  
}  
return -1;  
}  
 
 
var bookList = ["Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy", "Joshua", "Judges", "Ruth", "1 Samuel", "2 Samuel", "1 Kings", "2 Kings", "1 Chronicles", "2 Chronicles", "Ezra", "Nehemiah", "Esther", "Job", "Psalms", "Proverbs", "Ecclesiastes", "Song of Solomon", "Isaiah", "Jeremiah", "Lamentations", "Ezekiel", "Daniel", "Hosea", "Joel", "Amos", "Obadiah", "Jonah", "Micah", "Nahum", "Habakkuk", "Zephaniah", "Haggai", "Zechariah", "Malachi", "Tobit", "Judith", "Ecclesiasticus (Sirach)", "Matthew", "Mark", "Luke", "John", "Acts", "Romans", "1 Corinthians", "2 Corinthians", "Galatians", "Ephesians", "Philippians", "Colossians", "1 Thessalonians", "2 Thessalonians", "1 Timothy", "2 Timothy", "Titus", "Philemon", "Hebrews", "James", "1 Peter", "2 Peter", "1 John", "2 John", "3 John", "Jude", "Revelation"];
 
var newList = [];
var bookNumber, bookName;
 
 
 
for (var i = 0; i < theParagraphs.length; i++) {
newList.push(theParagraphs[i].contents);
}
 
//add double digit sorting numbers
for (var i = 0; i < newList.length; i++) {
bookName = newList[i].split(" ")[0];
if (bookName == "1"||bookName == "2"||bookName == "3") {
bookName = newList[i].split(" ")[0] + " " + newList[i].split(" ")[1];
}
 
if (bookList.indexOf(bookName)<9) {
bookNumber = "0" +(bookList.indexOf(bookName)+1) + "_";
}
else{
bookNumber = (bookList.indexOf(bookName)+1) + "_";
}
newList[i] = bookNumber + newList[i];
}
 
//sort list
newList = newList.sort();
 
 
//this part removes the sorting-number
for (var i = 0; i < newList.length; i++) {
newList[i] = newList[i].replace(/^\d+_/g, "");
}
 
//paragraphs contents updated
for (var i = 0; i < theParagraphs.length; i++) {
theParagraphs[i].contents = newList[i];
}
 
 
}
 
app.doScript('app.main();',ScriptLanguage.JAVASCRIPT,undefined,UndoModes.ENTIRE_SCRIPT, undefined);



 

 

edit: added ^ to grep replace

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 1
Explorer ,
May 05, 2020

Copy link to clipboard

Copied

Wow, that works perfectly! Thank you so much. This is going to be a real time saver. I am very grateful!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 0
Community Beginner ,
May 05, 2020

Copy link to clipboard

Copied

I am glad to hear that. 

I have not tested it in too many scenarios yet. I suspect there will be issues along the way.

 

Please use at your own risk.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 1
Most Valuable Participant ,
May 05, 2020

Copy link to clipboard

Copied

I need it often because I typeset many Christian (Evangellical, Theological) books, but in German. But in German the order of the epistles is different and (this is not relevant here) the number of chapters and verses in the old testament and in Acts are different than in English, only messianic Bibles (like CJB) have the same chapter number and verse numbers.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 0
Community Beginner ,
May 05, 2020

Copy link to clipboard

Copied

If you want it to work with German Bibles you have to change the contents of the bookList array to the correct German book names. 

I know the chapter/verse can differ from translation to translation but as long as you put in the correct bookList that should not matter. 

 

Feel free to modify as you please. 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 1