Tag creative

Scripting an InDesign progress bar for presentations

InDesign using Scripts

This post has some prose, so I’ll provide you with an easy out, if you have only come for the free stuff: jump to the making of, or download directly.

If you need help with the script installation, Indesignsecrets has you covered. I put mine in the folder ~/Library/Preferences/Adobe InDesign/Version 8.0/en_US/Scripts/Scripts Panel

If you like it, consider a tiny donation. However much it helped you. I appreciate it.
flattr this!

As a designer, you tend to do a lot of presentations. Some more than others, but still: you better know your stuff. In a recent push to bring ultrabold’s (mostly) PDF presentations into the new decade, I suggested they finally switch to a widescreen default, as most of the clients have moved to screens that match the wider resolutions. Also, many of the PDFs are actually shown in-house on a widescreen TV. I’m hoping this will catch on.

But I also wanted to add a little flair to the actual slides, or pages if you will. As the recipient, I also enjoyed when there was a visual indicator of how far along a presentation was. Most of the time, this is a page number. If you are lucky, the total page number is displayed next to it, so you can actually make use of the information. But as a presenter, you don’t want your audience occupied with math all the time, so I figured some sort of progress bar, which is commonplace in the software industry, could provide the information on a more subtle level.

Many designers make their PDF presentations in Adobe InDesign, which is a great fit (I believe it is the best program Adobe has in their lineup). It is not intuitive how you would make something like a progress bar happen in InDesign, though. As the interface did not get me to where I wanted to be, I turned to Google DuckDuckGo, and the consensus was: use scripting. I happen to know some JavaScript, so this looked like a welcome out back to my code editor. I figured the script needed to read the total amount of pages, iterate over all pages and place a rectangle of the appropriate proportion. Easier said than done. I know nothing about InDesign’s object names and methods, so I read a lot of stuff and slowly pieced together a solution.

The current version of my œuvre pops up a dialog in which the designer can specify width and height of the progress bar, as well as top and right margins. I figured most bars would be placed on the right, but it should be easy enough to calculate an offset for the left side. In addition, it is possible to specify a range of pages, as it may be useful to omit the first and/or last page of the presentation. They are usually a welcome and thanks for listening note and don’t carry actual content.

The script then creates up to three elements, depending on your preference – an optional background fill color, the bar itself and an optional border. At the same time, three object styles are created, so you can adjust the appearance of the bar with your own stroke and background colors. The code to create new object styles is easy, once you have figured it out. It avoids creating duplicates by trying to get the name property of the style first as a check.

var fill_style;
try {
	fill_style = app.activeDocument.objectStyles.itemByName('Progress Bar Fill');
	var check2 = fill_style.name;
}
catch(error_message) {
	fill_style = app.activeDocument.objectStyles.add({
		name: 'Progress Bar Fill',
		strokeAlignment: StrokeAlignment.INSIDE_ALIGNMENT, 
		strokeWeight: 0, 
		strokeColor: 'None', 
		fillColor: 'Black'
	});
}

You can then apply the style to your page objects like this:

objPref.appliedObjectStyles = fill_style;

or pass it directly to the add() method:

appliedObjectStyle: app.activeDocument.objectStyles.itemByName('Progress Bar Outline')

The calculation of the actual progress bar width is rather easy (code is shortened):

for(var i=0; i<pages_total ; i++) {
	width = Math.round((progress_width/(pages_total-1))*i*100)/100;
}

The creation of the rectangle is pretty straightforward as well (code is shortened). The bounds variable is an array of coordinates: top, left, bottom, right.

var rectangle = app.activeDocument.pages[0].rectangles.add({
	geometricBounds: bounds,
	appliedObjectStyle: app.activeDocument.objectStyles.itemByName('Progress Bar Background')
});

I hope you get some use out of this. As this was my first dive into InDesign scripting, I’m sure it’s not perfect (as a matter of fact there is a debug flag in the script which enables various debugging messages). And I have benefitted of work others have done, mainly Jongware’s amazing HTML InDesign Help and countless people on StackOverflow who have had similar problems before me.
The dialog window was pieced together from various sample scripts that were present in InDesign.

Javascript is quickly becoming my favorite language. Who’d have thought only ten years ago? I’m excited. Next stop: Photoshop.

Download progressbar.jsx

the free wall

Designwiki - the free wall (beitrag von arno)'

ich weiss nicht, wer von euch alles die free wall verfolgt. ich erklaers kurz, das prinzip ist nicht neu: einer faengt an und macht ein bild, der naechste schliesst irgendwie daran an und malt weiter, dann kommt der naechste und so weiter, bis es ein ganz langer bilderteppich wird. die “free wall” ist ein projekt an der fakultaet, das der caspar programmiert hat und wo das ganze digital ablaeuft. dazu werden aus dem pool von designwiki nutzern jeweils die naechsten kandidaten ausgesucht und benachrichtigt, wann sie dran sind. wenns dann soweit ist, hat man 48 stunden zeit, um ein 800×600 pixel grosses bild zu machen, was an das des vorgaengers anknuepft. fuer die designer an der FH vielleicht genau das richtige.
jedenfalls war ich jetzt mal dran und wollte nur kurz bescheidsagen, dass ihrs euch anschauen koennt, wenn ihr wollt. ich hab beschlossen, mal wieder was anderes zu machen als sonst und weniger glanz und web. ich denke, es ist ganz witzig geworden und vielleicht hat ja der ein oder andere von euch ein paar gedanken dazu.
fuer den naechsten, der anknuepfen muss, hab ich auch einen einstieg bereitgestellt, falls der oder die ihn mag: anknuepfpunkt.

¥ bedeutet nicht antworten

vielleicht ist dasselbe auch euch schon mal passiert: ihr erhaltet eine SMS, die saetze sind aber offen formuliert und ihr wisst nicht so recht, ob ihr jetzt darauf antworten sollt, oder nicht. manche haltens einfach: der martin antwortet prinzipiell nie, andere antworten auf jeden fall, egal ob man dazu auffordert, oder nicht. auch das ist moeglich.
nach zahlreichen misverstaendnissen mit meiner freundin haben wir uns ein system ausgedacht, damit wir uns nicht mehr darueber in die haare kriegen, ob man jetzt haette zurueckschreiben muessen, oder nicht. da in einer normalen SMS recht wenige zeichen zur verfuegung stehen (160), ist es wenig praktikabel, jedesmal “bitte um antwort” dazu zu schreiben. daher sind wir auf die schlaue idee gekommen, zwei wenig verwendete zeichen mit ebendieser bedeutung zu versehen. die wahl fiel dabei (voellig beliebig) auf das Yen-Symbol ¥ und das Währungssymbol ¤

¤ beudetet: “auf diese SMS bitte antworten”
¥ beudetet hingegen: “auf diese SMS musst du nicht antworten”

das bitte-um-antwort symbol brauche ich nicht so haeufig, aber das Yen-Zeichen erfreut sich seither grosser beliebtheit. oft schreiben wir nur, was uns gerade so passiert und das erfordert in der regel keine antwort. das zeichen setzen wir normalerweise als letztes symbol in die SMS. damit spart man sich viele misverstaendnisse, versprochen. kommentare: ¤