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

Script to sort list of Bible references in Bible order

Explorer ,
Apr 23, 2020 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.

TOPICS
Scripting

Views

3.4K

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
community guidelines

correct answers 1 Correct answer

Explorer , May 05, 2020 May 05, 2020

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;  
}
...

Votes

Translate

Translate
Community Expert ,
Apr 23, 2020 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. 

Votes

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
community guidelines
Community Expert ,
Apr 24, 2020 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?

Votes

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
community guidelines
Explorer ,
Apr 24, 2020 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

 

Votes

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
community guidelines
Explorer ,
May 04, 2020 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

Votes

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
community guidelines
Community Expert ,
May 05, 2020 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

Votes

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
community guidelines
Explorer ,
May 05, 2020 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

Votes

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
community guidelines
Explorer ,
May 05, 2020 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!

Votes

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
community guidelines
Explorer ,
May 05, 2020 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.

Votes

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
community guidelines
New Here ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

Basically your script works great. Thanks for that. Unfortunately, some of the formatting of the text has been shifted. Do you have an idea what could be the reason for that?

 

sortet_bibletext_formatting_failure.jpg

Votes

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
community guidelines
New Here ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

As is just have seen the numbers do not seem to be correctly taken into account in the sorting process. In this respect the script is unfortunately useless

Votes

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
community guidelines
New Here ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

Well, not quite, as a turnaround InDesign's Sortparagraph-Script can be used to sort the individual sections to the end. Thanks anyway!

Votes

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
community guidelines
Explorer ,
Oct 29, 2020 Oct 29, 2020

Copy link to clipboard

Copied

Yeah, the script currently does not take into account the possibility of multiple text styles per paragraph.

Votes

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
community guidelines
Explorer ,
Oct 29, 2020 Oct 29, 2020

Copy link to clipboard

Copied

Update:
Script now keeps styling while sorting.
(Still clunky and potentially faulty. Use at your own risk.)
 
 
Application.prototype.main = function() {
var theDoc = app.activeDocument;
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;  
}  
 
 
//List of Bible booknames in correct order
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 = [];//array to hold numbered list of booknames
var sortedList = [];//array to hold numbered and javascript sorted list of booknames. Just text no styling.
var bookNumber, bookName;
 
for (var i = 0; i < theParagraphs.length; i++) {
newList.push(theParagraphs[i].contents);
sortedList.push(theParagraphs[i].contents);
}
 
//add double digit sorting numbers to newList array
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];
sortedList[i] = bookNumber + sortedList[i];
}
 
//sort text list
sortedList = sortedList.sort()
 
//Make temporary text frame to hold paragraphs with styling
var newFrame = theDoc.pages[0].textFrames.add();
var newStory = newFrame.parentStory;
 
for (var i = 0; i < theParagraphs.length; i++) {
theParagraphs[i].duplicate(LocationOptions.AT_END,newStory);
}
var newParas = newStory.paragraphs.everyItem().getElements();
 
 
//add double digit sorting numbers to paragraphs in new frame
for (var i = 0; i < newParas.length; i++) {
var paraContent = newParas[i].contents;
bookName = paraContent.split(" ")[0];
if (bookName == "1"||bookName == "2"||bookName == "3") {
bookName = paraContent.split(" ")[0] + " " + paraContent.split(" ")[1];
}
 
if (bookList.indexOf(bookName)<9) {
bookNumber = "0" +(bookList.indexOf(bookName)+1) + "_";
}
else{
bookNumber = (bookList.indexOf(bookName)+1) + "_";
}
newParas[i].insertionPoints[0].contents = bookNumber;
newParas = newStory.paragraphs.everyItem().getElements();
}
newParas = newStory.paragraphs.everyItem().getElements();
 
 
//find the correct order based on the sorted list
for (var i = 0; i < sortedList.length; i++) {
var paragraphToMove = newList.indexOf(sortedList[i]);
theParagraphs[i].contents = "";
var movedPara = newParas[paragraphToMove].move(LocationOptions.before, theParagraphs[i]);
movedPara.characters.itemByRange(0,2).remove();
}
//remove temporary text frame
newFrame.remove();
 
}
app.doScript('app.main();',ScriptLanguage.JAVASCRIPT,undefined,UndoModes.ENTIRE_SCRIPT, "sortBibleBooks_v2");

Votes

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
community guidelines
Participant ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

This script is awesome, thanks SO much! I'm using it for sorting a Scripture index which has headings with the name of the book, and then the index, like so: 

Genesis

    Genesis 1

    Genesis 2

Exodus

    Exodus 5

    Exodus 6

 

Unfortunately, this script separates the headings from the entries (which have numbers after them). 😞 😞 So after sorting, all the headings have been sorted separately at the beginning of the index, and then the entries were sorted separately after that. Is there any way to modify the script so that it leaves the heading without a number as the first, and then lists all other entries after it? 

Votes

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
community guidelines
Participant ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

I figured out a simple solution to this problem. I just added "00" to the headers so that they'd show up before any of the other chapters. 🙂

Votes

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
community guidelines
Explorer ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

Great that you found a solution. 🙂

Votes

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
community guidelines
Participant ,
Mar 03, 2022 Mar 03, 2022

Copy link to clipboard

Copied

Yeah, why didn't I think of that solution first thing? 🙂 It's crazy how the simplest solution sometimes takes a while to "hit" home. Did you see my post about the more serious sorting issue though? I'm hoping there's a simple solution for that one too, but it hasn't come to me yet. 

Votes

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
community guidelines
New Here ,
Apr 08, 2023 Apr 08, 2023

Copy link to clipboard

Copied

Could you please show me a full example of this being invoked and sorting a short list of references? This is just what I need, but I do not know how to use it.

Thanx in advance for all you do to help others.

Bob D.

Votes

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
community guidelines
New Here ,
Apr 08, 2023 Apr 08, 2023

Copy link to clipboard

Copied

Sorry for being such a newbie, but could anyone show me a full example of this being invoked and sorting a short list of references? This is just what I need, but I do not know how to use it.

Thanx in advance for all you do to help others.

Bob D.

Votes

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
community guidelines
Community Expert ,
Apr 09, 2023 Apr 09, 2023

Copy link to clipboard

Copied

LATEST

As outlined in the other post, the simplest method is to add leading zeros to numbers so that they're all the same length. Do two find-change queries:

The first one adds two zeros to single-digit numbers:

Find what: \b(\d)\b
Change to: 00$1

The the second query adds a single zero to double-digit numbers:

Find what: \b(\d\d)\b
Change to: 0$1

 Now sort your index. Then remove the leading zeros in one query:

Find what: 0+\d
Change to: <leave empty>

P.

Votes

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
community guidelines
Community Expert ,
May 05, 2020 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.

Votes

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
community guidelines
Explorer ,
May 05, 2020 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. 

 

Votes

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
community guidelines