The Shortest-Ever Aphorism Generator
September 12, 2012 | Tips | en
As an InDesign scripter, you probably know that PageItems
, Paragraphs
—or any other collection—exposes a method named anyItem()
which randomly digs up a sample in the set. The only question is: what the hell can it be used for?
While still pondering the matter, I suddenly realized that Words.anyItem()
is a great way to select a random word in a text. Then I came up with this tiny script:
// Consider a story // --- var story = app.activeDocument.stories[0]; // Take a word in every paragraph of the story // --- var words = story.paragraphs.everyItem(). words.anyItem().contents; // Join the array // --- alert( words.join(' ') );
Stupid, isn't it?
Now suppose that our story has the following paragraphs:
the all any every¶
cat dog snake man¶
is has eats¶
a¶
white red orange wild¶
hat banana apple¶
The above script will then display a random sentence such as: “the snake has a red hat.” In fact, the story can lead to 4×4×3×1×4×3 = 576 distinct sentences! We are not far from Queneau’s A Hundred Thousand Billion Poems, are we?
Of course it is your business to fuel the pattern creatively. If you want InDesign to become a philosopher, get inspired by the Aphorism Generator by Joe Halliwell (after Paul Braffort) and try something like this:
…then launch the script with this slight modification:
var story = app.activeDocument.stories[0]; var words = story.paragraphs.everyItem(). words.anyItem().contents; alert( words.join(' ').replace(/[_ ]+/g,' ') + '.' );
Here is one of the truths InDesign taught me today:
“Doubting might be the silent modernity of courage.”
Comments
Thanks for sharing this tiny but amusing script.
I never thought something so dogmatic as code could create something so uninhibited as art. thanx
Thats really funny. You could make a great blog just for this. Just think how amazing the blog would be. Great work.