-
Scripting an InDesign progress bar for presentations

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 user=”oelna” title=”Blog: InDesign Progress Bar with Scripting” url=”http://oelna.de/blog/?p=779″]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
GoogleDuckDuckGo, 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.
-
Girls
I don’t particularly like test-driving a new TV show. You always risk wasting your evening on something like “Body Of Proof”, which disappointed me earlier this month. But sometimes you find a gem. After “How I Met Your Mother” has become so stale and some other shows have reached their pinnacle as well, I had to find something new, so I took a chance and started Girls, which just ended its first season with Episode 10. I have to say, I was surprised it was this entertaining, and truly well made TV. I consider it something of a complement to “New Girl” (which I also kind of enjoy, but is on summer break), but with a more serious undertone; more of a drama-soap than comedy. Just what I needed. If anybody is in search for something to fill their evening, I highly recommend looking into it. Not too heavy, not too long (I’m looking at you, “Sherlock”!) and occasionally really funny. Thumbs up.
Trailer: http://youtu.be/0QyyuM3CzSs
Comments
Leave a Reply
-
Diablo 3 Builds
Ich dachte, ich notiere hier mal kurz meinen Fortschritt in Diablo 3 und damit meinen Softcore Level 47 Build und den Hardcore Level 16 Build. Das sind eigentlich die meistgespielten Charaktere bei mir.
Am meisten gings mir aber darum, das Battle.Net Tooltip-Script mal in einen Post einzubauen, damit ich das schnell zur Hand hab, wenn ichs dann mal brauche. Ich denke, man kann jetzt wahrscheinlich auch in den Comments Items, Skills und Builds posten, indem man einfach auf die Seite verlinkt, oder den Link direkt postet.
Comments
-
Schau an, es geht:
http://us.battle.net/d3/en/calculator/wizard#aePQXj!bYX!ZaZZZa
Leave a Reply
-
-
A Super Mario Summary
Shaun Inman is right about the controls, but the overall game is still lovely, so I decided to post it. Recreates all original Super Mario levels, but on a single screen each. A great idea with beautiful graphics. By Johan Peitz.
Comments
Leave a Reply
-
Goodbye Bluray, goodbye DVD!
And good riddance. Who even *owns* a player that can play DVD or Bluray anymore?! Alfred Poor’s HDTV Almanach:
New research by IHS Screen Digest Research predicts that in 2012, U.S. consumers will pay to watch more movies online than they will watch movies recorded on DVD and Blu-ray discs.
Comments
Leave a Reply

Comments
Hey! This is great, very useful for presentations!
I had this problem cause my presentations were all fullscreen and people was geting confused about the navigation and the content.
Your script is very easy to use yet very powerful. Loved the dialog box, very simple and useful.
Keep up the good work!
Im Jon from Brazil
Jon, thanks for the kind words. It’s great to see somebody is getting use out of it. Thanks for taking the time to comment.
I noticed that its better to execute the script over a new layer, in case you have to add or remove pages, and then execute the script again, its easy to undo if its all in a layer above.
Maybe you can include that to the script in the future, to create a new layer on top and then populate the pages with the bar!
A great idea. I will definitely look into it. However, I usually create the layer myself, as I don’t like too many things happening automatically. This way, I can decide for myself whether I need it on a new layer or not.
I may make it a checkbox option in the popup window. This way, everybody wins. Thanks for your suggestion!
hi, this is amazing! Is there a way to get this to go vertical rather than horizontal?