There is a standard script to sort multiple paragraphs alphabetically in InDesign, but I am looking for a script to sort words within a single paragraph alphabetically. Does anyone know of such a script?
Not aware of such a script but it's very easy to combine a selection Grep Find/Change with SortParagraphs.jsx
Select your paragraph, open the Find/Change panel.
In the Grep tab, replace spaces by paragraph returns. Find \s, change \r
Make sure to change selection only.
With all the content still selected, run the SortParagraphs script, then revert the process by changing paragraph returns by spaces.
A friend of mine has provided me with the answer:
app.selection.contents = app.selection.contents.split(/\s+/).sort().join(" ")
Thanks to Harbs.!