I found an awesome little script here that sorts the books of the Bible in canonical order but I just now noticed a strange bug, and I'm not sure what is causing it. 😞
I am generating a Scripture Index at the back of my book in InDesign, using character styles and then Peter Kahrel's great little "Index from Character Styles" script. After I generate the Index, I end up with a list of scripture references in alphabetical order with page numbers after them like this.
Now I need to sort this entire scripture index to be in canonical order (instead of alphabetical order). But after selecting the text and running the sorting script, I end up with this 😞 :
The books are in the correct order, but the chapter numbers are all out of sync! 😞 I suspect that it's the page numbers that are throwing the script out of whack, but I can't verify that, and neither do I know what to do to fix it. I'm slowly learning some simple scripting in InDesign, but this script is a bit above me yet. Does anyone have any pointers for me? @Magnus Gaarde is the one who wrote the script, but I don't know if they are still around on the forums or not.
Thank you in advance if you can help me out!
Copy link to clipboard
The script will sort the list based on the characters in the name. 1 comes before 2 etc.
That is why the sorting will look as in your example:
The script was written tocould quickly sort a list of Bible books for a contents page or similar. It was not intended to sort an entire index.
If you are able to GREP your way out of adding couple of zeros to the first chapter numbers that might get the sorting right.
I guess I (or somebody else) could rework the script if I had the time. But at the moment I don't have that time. Sorry.
I hope you find a way to work it out.
Thanks so much @Magnus Gaarde for your reply. I realize that I'm probably asking more of the script than it was originally intended to do, but I wasn't even sure how it worked when I first ran across it. Now that I know how it works, hopefully a solution can be found. 🙂 Your idea about padding with zeros is a good one, I'll have to see if I can figure out some way to temporarily do that, and then remove the padding again after everything is sorted. Thanks again for your time on this; I really appreciate it!
@Magnus Gaarde I figured out the grep code to add padding zeroes and then remove them again afterwards. I don't have any trouble adding them to the selection before the main sorting script runs, but after the sorting script is done, the text is no longer selected, so I can't run my code to remove the padding zeroes on the selection. Is there way to keep the text selected after the code is done running so that my GREP code can run on the selection?
It's probably not necessary to run your script against a selection since you want to add leading zeros to all items. Try this:
target = app.selection.parentStory; // Set up your GREP expression to add leading zeros, then: target.changeGrep(); // Set up your GREP expression to delete leading zeros, then: target.changeGrep();
Exactly. As Peter mentions, running the changeGrep on the story must be the easiest way in this case.
(You can also run it on the entire document: app.activeDocument.changeGrep();
Or on the app itself affecting all open documents: app.changeGrep();
However, this can be dangerous.)
@Magnus Gaarde I have another slight issue. There are some books of the Bible (like Obadiah, Philemon, 2 John, 3 John, and Jude) that only have one chapter. In that case we usually just refer to it as "Jude" without a chapter number. But when I add Jude to the index (with a comma after it; then the list of page numbers) then the sorting script seems to choke on it, and it throws Jude (and any other one-chapter books) to the beginning of the list, even though it belongs near the end. It worked before when I had a space after Jude, like this: 'Jude ,' but when I removed that unnecessary space, then I noticed this issue. Should I just remove the space after sorting, or is there a better fix for this? Thanks!
> Should I just remove the space after sorting, or is there a better fix for this?
This seems to be the simplest method.
At this point I would say that if it works by removing the space after sorting, that's your solution.