InDesign tip : #31

the last couple of scripting lessons (#30 & #31) showed a couple of examples of how to use applescript to assist with reformatting an existing table. but if you are setting up your own tables you’d use table and cell styles to make your life a little easier.

as with paragraph, character and object styles — if you are going to use particular formatting settings more than once in a document, it’s smart to create a style for those settings. so, if your document has several tables with similar formatting, you’d create a table style. this example only has one table, so we’ll just look at cell styles.

when we first change our text to a table it will look something like this :
screen grab of unformatted table

then we start to create the table formatting we want :
screen grab of partially formatted table

to create the cell style for the reversed row, highlight that row and then choose “New Cell Style…” from the flyout menu on the cell styles panel (windows > styles > cell styles) :
screen grab of cell styles panel flyout menu

you can also access this functionality directly from your control panel :
screen grab of cell styles menu in control panel

the new style takes on the formatting of the selected cells. we’re calling that style ‘header row’ and you can see that, as well as the colour of the cells, the cell style will also apply a paragraph style to the text in those cells. that is, the paragraph style does not need to be applied separately — it’s part of the cell style :

then repeat the process for each different cell type. for this table we’ve created three different cell styles :
screen grab of new styles in cell styles panel

the easiest way to proceed from here is to first apply the most common style to the entire table. to select every cell in a table, first place your cursor somewhere within the table and then move your mouse to the top left corner of the table until you see a downward pointing arrow, then click.

here we’ve applied the ‘basic row’ style to the entire table by clicking that style in the cell styles panel (or from the control panel dropdown) :
screen grab showing entire table with bsaic row style applied

then go through and apply the other styles to their relevant cells (here we’re doing entire rows in the same style) :
screen grab of table with complete formatting

now here’s why you’ve gone to all that trouble … when the client comes back and says they want all the reversed rows to be thicker and all the blank rows to be thinner (or any of a gazillion other possible alterations), you don’t have to change each row individually (or use applescript) you just change the cell styles. unfortunately InDesign does not yet allow you to specify a specific cell height in the cell style (who knows why), but you CAN change the spacing — or cell insets. here we’re changing the top and bottom insets for the ‘header row’ style from 1mm to 2mm :
screen grab showing cell style options for the header row style

and like magic the entire table is updated automatically :

so, if you’re working with tables but not using cell styles, you’re probably working way too hard.

macgrunt icon


InDesign tip : #30

adding automatic page numbering to your InDesign document is easy. just create a text frame on your master page and then hit cmnd-opt-shift-N or choose this from your Type menu :
screen grab of insert special character flyout menu
you can style the page number the same way as you would any other text. if you type in “page ” before the page number, your master page will look like this :
screen grab of master page with basic page numbering
and your document page looks like this :
screen grab of document page with basic page numbering
but you probably already knew that.

you’ll notice that in the insert special character flyout menu there are a few other markers including one called ‘section marker’ which we’ll talk about in a moment. but there’s no marker for ‘total pages’ — so how do we get automatic numbering in this format? :
screen grab of extended page numbering on document page

well, it’s a bit of a mystery why adobe decided to put that particular functionality in a different place. but here’s where you’ll find that second special character from the Type menu :
screen grab of text variables flyout menu

ok, now, you can also add a ‘section marker’ from the insert special character flyout menu. on the master page it looks like this :
screen grab of master page showing complete numbering line
just to make things clear, that’s : {section marker}+” ~ page “+{current page number marker}+” of “+{last page number text variable}

then you need to specify what you want the section marker to say — under your numbering and section options :
screen grab of numbering and section options

which will render your document page thus :
screen grab of document page showing complete numbering line

so far so good.

the last page number text variable is just a tad clunky — even in CS6. so far we’ve been looking at page two of this document :
screen grab of pages panel showing six pages in two sections
six pages with a two-page section followed by a four-page section. and the text variable has been used with these options :
screen grab of last page number text variable options
notice that the scope is set to ‘section’. so we get ‘2 of 2’ because there are only two pages in the section.

but, if we change the scope to ‘document’ we don’t get ‘2 of 6’ :
screen grab of page numbering showing '2 of 4'

why? because the text variable is for ‘last page number’ (4) not ‘total page count’ (6). your challenge is to come up with even one scenario where you’d want to number your pages in that fashion.

you’d have to agree that that’s pretty crap. at the very least, InDesign should offer the option to use absolute page numbering for that text variable — maybe one day.

macgrunt icon

InDesign tip : #29

adobe’s prerelease program is a brilliant way to contribute to the development of future software releases. this is what adobe has to say about the program :

“The goal of a Prerelease Program at Adobe is to solicit early feedback on new features and bugs in order to produce a unique and a bug free product that can deliver maximum results.”

it’s not something you can just sign up for — you have to apply, giving your areas of expertise, years of experience, etc. and if adobe think you may have something to contribute you’re in. you can apply to be part of adobe’s prerelease program here

if you get accepted into the program you get a sneak-preview of some of the cool stuff currently in development — some of it is just tweaks to existing tools — some of it doesn’t make the cut because it just doesn’t work, or whatever — but some of it is truly awesome — like this new menu that’s in the very early stages of development :
screen grab of beta design menu
(apologies, the conditions of the prerelease program forbid showing screen grabs of the actual functionality)

the top few menu items are pretty clunky at this early stage and will probably only be useful to talentless desktop publishers in the first few incarnations of this menu. but the basic concept is sound and there’s already quite a bit of evidence from the beta-testing that one day these will be really powerful features of InDesign.

the last two menu items are the ones with immediate application for designers. as you can probably guess, these allow for quickly testing different colour sets and font sets throughout a document. these rely on the user correctly assigning swatches and type styles onto which the test colours and fonts can be temporarily mapped. if you’re happy with the results, just confirm your choice and all your swatches and/or type styles are updated accordingly. a cool thing about this functionality is the capability to switch between up to three different colour sets and font sets — giving you all the experimental scope you need.

adobe keep things pretty tight, so it’s hard to know if this menu will make the cut for CS7. there is a positive vibe on the review forums, but there’s also a lot of concern about some of the more obvious bugginess — so it might be a bit longer before we see this menu released for real.

if you’re excited by this kind of future functionality, then you’re exactly the kind of person that adobe needs to help with testing and reviewing. so apply for the prerelease program and have your say.

keep grunting

macgrunt icon

InDesign scripting : lesson 27

here is a variation on the slug form script from lesson 25. this version does not use a pre-existing form on the page — it creates a simple text frame holding information similar to the ‘page information’ you can add to your printouts, with three important improvements : it’s more readable ; it includes the page dimensions and ; it includes the user name.

the full version of the script prints the document and exports a pdf to an email attachment — functionality that you can find lessons for elsewhere on this site. today we’ll just focus on the core problem of creating the slug info which will look something like this :
screen grab of slug information

the first part of the script demonstrates a handy little scripting trick — the script property :

property mgUser : ""

if mgUser is "" then
  --bit to collect new user name
  tell application id "com.adobe.InDesign"
    set mgDialog to make dialog
    tell mgDialog
      tell (make dialog column)
        tell (make dialog row)
          make static text with properties {static label:"Enter the name you'd like to be known by."}
        end tell
        tell (make dialog row)
          set mgTextField to make text editbox with properties {edit contents:"Who you then?", min width:250}
        end tell
        tell (make dialog row)
          make static text with properties {static label:"(you won't be hassled with this again)"}
        end tell
      end tell
    end tell
    set mgResult to show mgDialog
    if mgResult is true then
      set mgUser to edit contents of mgTextField as string
      destroy mgDialog
      error number -128
      destroy mgDialog
    end if
  end tell
end if

you’ll notice that we set the property mgUser to “” right at the start, and then go on to ask if mgUser is “”… — now that might seem nonsensical, but it’s not — because script properties have persistent data. the first time we run the script mgUser starts off as “” but is given a different value by the user when they enter their name in the dialog that’s generated (eg. ‘macgrunt’). that new value gets saved as an integral part of the script so that the next time it is run mgUser is “macgrunt”, not “”. by wrapping that whole script in an if/then statement, we ensure that the user only has to enter their name the first time the script is run. every subsequent run skips everything down to the second last line — mgRunThisSucker().

the user will be presented with a dialog something like this :
screen grab of user dialog
of course, you can change the various text elements in that dialog to read however you like.

the next part of the script captures a bunch of data we need :

on mgRunThisSucker()
  with timeout of 36000 seconds
    set mgHour to do shell script "date '+%H'"
    set mgMinute to do shell script "date '+%M'"
    if mgHour is less than 12 then
      set mgAmPm to "am"
      set mgAmPm to "pm"
    end if
    if mgHour is more than 12 then
      set mgHour to mgHour - 12
    end if
    set mgDate to do shell script "date '+%d/%m/%y'"
    set mgDate to mgDate & "  :  " & mgHour & ":" & mgMinute & mgAmPm
    tell application id "com.adobe.InDesign"
      tell active document
        set mgName to name
        set mgFolder to file path
        set text item delimiters of AppleScript to "."
        set mgShortName to text item 1 of mgName
        set text item delimiters of AppleScript to ":"
        set mgClient to text item -4 of (mgFolder as string)
        set text item delimiters of AppleScript to ""

we’re capturing both the date and time for this version of the slug form. notice that …”date ‘+%H'” captures the hours in 24-hour time — but we want our time to appear as “2:00pm” rather than “14:00” — hence the bit of extra mucking around. if you’re happy with 24-hour time you could capture mgDate like this :

do shell script "date '+%d/%m/%y  :  %H:%M'"

note also that the way you capture mgClient depends on where the InDesign file sits in your folder hierarchy — text item -2 of (mgFolder as string) is the folder containing the InDesign file — text item -3 of (mgFolder as string) is the next folder up, etc.

next we create a layer and paragraph style for the slug information (if they don’t already exist) and the slug offset at the bottom of the page :

          set mgLayer to layer "SLUG"
          set locked of layer "SLUG" to false
          delete every text frame of layer "SLUG"
        on error
          set mgLayer to make layer with properties {name:"SLUG"}
        end try
          set mgPara to paragraph style "SLUG"
        on error
          set mgPara to make paragraph style with properties {name:"SLUG", justification:left align, point size:7, applied font:"Minion Pro  Regular", fill color:"Black"}
        end try
        set mgBleed to document bleed bottom offset of document preferences
        set mgSlug to mgBleed + 5
        if slug bottom offset of document preferences is less than mgSlug then
          set properties of document preferences to {document slug uniform size:false}
          set properties of document preferences to {slug bottom offset:mgSlug}
        end if

the first part has a couple of try blocks — the first time the script is run on a particular file it will create a new layer and para style — but on subsequent runs the layer and style will already exist and trying to create them again will cause an error. so, instead, we cover off all eventualities with the try blocks. notice that the first try block deletes all the text frames on the slug layer — new frames are created with fresh content on each run. the rest of that part of the script is dedicated to setting the slug offset to 5mm outside the bleed (unless it’s already bigger than that).

the next part captures the rest of the data we need and puts all the elements together into one long text string (mgContents) :

        repeat with mgspread from 1 to count spreads
          set active spread of layout window 1 to spread mgspread
          tell active spread of layout window 1
            set mgPage to name of page 1
            set mgWidth to item 4 of bounds of page 1
            set mgWidth to mgWidth as integer
            set mgHeight to item 3 of bounds of page 1
            set mgHeight to mgHeight as integer
            set mgDimensions to ((mgHeight as string) & "x" & mgWidth as string) & "mm"
          end tell
          set mgContents to mgShortName & "  :  " & mgClient & "  :  page " & mgPage & "  :  " & mgDimensions & "  :  " & mgUser & "  :  " & mgDate

notice that we’ve opened a repeat loop here — because we want to add a separate slug to each spread (this script was created for a workflow where it is possible that a single file could have pages of varying sizes).

and finally the last bit — create the text frame, fill it with text, style the text, move the frame to the right layer and, when all frames are done, lock the layer so it can’t be inadvertently used for other content :

          set mgBounds1 to mgHeight + mgBleed
          set mgBounds3 to mgBounds1 + 4
          set mgFrameBounds to {mgBounds1, "0", mgBounds3, mgWidth}
          set mgSlug to make text frame in page mgPage with properties {geometric bounds:mgFrameBounds, fill color:swatch 1}
          set properties of text frame preferences of mgSlug to {inset spacing:{0, 2, 0, 2}}
          set vertical justification of text frame preferences of mgSlug to bottom align
          set contents of mgSlug to mgContents
          set applied paragraph style of parent story of mgSlug to "SLUG"
          move mgSlug to layer "SLUG"
        end repeat
        set locked of layer "SLUG" to true
      end tell
    end tell
  end timeout
end mgRunThisSucker

cobble all that together and you’ll have a script that looks something like this :
screen grab of entire script in script editor

save that as a script (.scpt) into your scripts panel folder. as discussed in the previous post, lesson 26, if you save it in text format (.applescript) the property mgUser will not be saved as persistent data and will have to be entered every time the script is run — and that would be tedious.

if you can’t be bothered compiling this yourself, you can go here to get the complete slug script

keep grunting

macgrunt icon

InDesign tip : #28

with a little bit of effort you can turn poor typography into ok typography in your body copy. unfortunately, InDesign doesn’t really allow for great typography — but that’s something we’ll touch on in a moment. this post is about automatic kerning, justification and hyphenation.

the first thing to check when you’re working with a particular font is what result you get with each of the automatic kerning options — metrics and optical. which one of those is best for a particular font depends on how good the type designers were at doing their job.

when you choose metrics you are using the mathematical settings created by the typographer. a well created font will have metrics for all the most common character pairs — specifying, for example, the amount of space that should appear between ‘AB’, which will (at least, should) be different from the amount of space that appears between ‘AV’. these metrics are generally known as kerning tables.

when you choose optical you are asking InDesign to override the typographer’s kerning tables and space the characters more or less visually based on the shapes of the characters.

here are a couple of screen grabs showing the same portion of text using the two different automatic kerning methods :
screen grab of text set with metric automatic kerningscreen grab of text set with metric automatic kerning

as you can see, neither of these methods is perfect. ‘his’ and ‘and’ are undoubtedly better using metrics kerning, but ‘winston’ and ‘musing’ are better when using optical kerning — the metrics don’t come up to scratch. and this for a font called Adobe Garamond Pro — you would think we should expect better from the metrics.

and here’s why InDesign doesn’t allow for great typography and why, in at least this one aspect, Quark shits all over InDesign. with Quark you have the option to correct dodgy metrics by editing the kerning tables. so, with Quark we could get in there and fix that diabolical ‘mu’ combination in the kerning table and then it would be corrected for every instance throughout the entire document. InDesign allows no such finessing — we are stuck with the shitty kern-pairs that come with the font or we take our chances with optical kerning.

so, when working with a new font, always check both automatic kerning methods to see which will give you the least disappointing results.

ok, now on to justification. the default justification settings that come with InDesign are simply insane and lead to this kind of abomination :
screen grab of poorly justified type

this is because the default justification settings look something like this :
screen grab of poor justification settings

those numbers are invariably going to lead to shit results. all the adjustments to a line of text happen between the words — none between the individual characters — and those adjustments range from 133% word spacing (big gaps) down to 80% (words running together).

settings which make just a little more sense look something like this :
screen grab of better justification settings

… and will lead to better results — not perfect, but better :
screen grab of better justified type

right, last we have hyphenation and, again, the defaults are ludicrous :
screen grab of default hyphenation settings
just the fact that automatic hyphenation is turned on by default is silly enough — because InDesign is not that great at deciding where a hyphen should appear within a word. but the rest of those settings will, AGAIN, invariably lead to shit results — like this :
screen grab of text using default hyphenation settings
four hyphens in the first seven lines and the very first word on the page is the second half of a word from the previous page — just atrocious.

most jobs do not require automatic hyphenation — you should add your own (discretionary) hyphens, where appropriate, as you set the text. if you really must use automatic hyphenation (eg. you’re laying out vast tracts of text like a novel) then you should uncheck all those check boxes and adjust the other settings to something more like this :
screen grab of better hyphenation settings

the improvement to the type is simply indisputable :
screen grab of text using better hyphenation settings

but wait, there’s more …
once you come up with a bunch of settings which suit your sensibilities you can make them your very own defaults — just the same as you can change so many of InDesign’s default settings. just make sure you have no documents open then adjust the justification and hyphenation settings through the paragraph panel (under the type menu) :
screen grab of paragraph panel and dropdown menu
those will be your new defaults for every new document from now on.

keep grunting

macgrunt icon