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

renaming finder items III

renaming finder items introduced a couple of ways to batch-rename files in the finder — using automator or applescript — by replacing characters or removing parts of the file name. renaming finder items II showed how to map a bunch of files to a completely different set of file names.

Applescript Icon this post will show another way to rename files — based on their creation date — using applescript. this workflow came about due to the diabolical way that digital cameras name their files. here’s a screen grab of a typical bunch of images :
screen grab of folder of images with diabolical file names

for this workflow, we’d like the order of the filenames to match the date the photo was taken — to make sorting, selecting, archiving, etc. just a little easier. the current naming is made more problematic because files are coming from more than one camera. well, we don’t have to put up with that crap — let’s just rename them.

set mgFolder to choose folder
tell application "Finder"
  set mgFiles to items of mgFolder
end tell
repeat with mgFile in mgFiles
  set mgPath to POSIX path of (mgFile as string)
  set mgCreation to creation date of mgFile
  set mgDate to short date string of mgCreation
  set mgTime to time string of mgCreation
  
  -- rest of script here
end repeat

first we get the user to select a folder of images to process, then we get references to the files in that folder, then we start a repeat loop to process each file in turn. we capture the following information :
mgCreation – for example “Thursday, 4 October 2012 17:13:18 ” – from which we extract :
mgDate – “04/10/12” (that’s dd/mm/yy) and
mgTime – “17:13:18 ” (that’s hh/mm/ss)

if you find that mgDate or mgTime give you the data in a different format, you will need to update the next part of the script accordingly or, if you prefer, change your language and text system preferences :
screen grab showing language and text system preferences window

we’re going to use mgDate and mgTime to create a file name like this “yymmdd_hhmmss” — so, we need to strip out the slashes and colons, reverse the order of the date, and introduce an underscore :

  set text item delimiters of AppleScript to ":"
  set mgTime to text items of mgTime --gives {"17", "13", "18 "}
  set text item delimiters of AppleScript to "/"
  set mgDate to reverse of text items of mgDate --gives {"12", "10", "04"}
  set text item delimiters of AppleScript to ""
  set mgDate to mgDate as string --gives "121004"
  set mgTime to mgTime as string --gives "171318 "
  set mgTime to text items 1 thru 6 of mgTime as string
  
  set mgNewName to mgDate & "_" & mgTime

this uses the handy “reverse of” command — taking a list of items and rearranging them in reverse order. also notice the second last line — we need that because mgTime has a trailing space we need to get rid of. this method works no matter how many trailing spaces there are because we’re saying “just give me the first six characters and ditch the rest”.

now, that’s the bulk of the script done — we also need to capture the extension of the file (mgExtension), create a filepath for the renamed file (mgFinalPath), and then do the renaming with a shell script. the shell script basically says — move this file, without any prompts, from this filepath to that filepath (you could also use this method to move the file to a completely different location — but we’re just renaming the file and leaving it in the same location) :
danger : do not run this next script — it is for demonstration purposes only – you’ve been warned!

set mgFolder to choose folder
tell application "Finder"
  set mgFiles to items of mgFolder
end tell

repeat with mgFile in mgFiles
  set mgPath to POSIX path of (mgFile as string)
  set mgCreation to creation date of mgFile
  set mgDate to short date string of mgCreation
  set mgTime to time string of mgCreation
  
  set text item delimiters of AppleScript to ":"
  set mgTime to text items of mgTime
  set text item delimiters of AppleScript to "/"
  set mgDate to reverse of text items of mgDate
  set text item delimiters of AppleScript to "."
  set mgExtension to text item -1 of (mgFile as string)
  set text item delimiters of AppleScript to ""
  set mgDate to mgDate as string
  set mgTime to mgTime as string
  set mgTime to text items 1 thru 6 of mgTime as string
  
  set mgNewName to mgDate & "_" & mgTime

  set mgFinalPath to mgFolder & mgNewName & "." & mgExtension as string

  do shell script "mv -f " & quoted form of POSIX path of mgPath & space & quoted form of POSIX path of mgFinalPath
end repeat

if we run this script on that original folder of images we’ll get this :
screen grab of file names after processing with first script

well, that looks pretty good at first glance — all the files have been renamed successfully … except … the very observant will notice that this folder has only 81 items, whereas the original folder had 103. wtf?

the problem is that it’s quite possible to have more than one file with a creation date of “04/10/12 17:13:18” — digital cameras can flick off quite a few images in a second. the script in its current form will simply write over a file with a duplicate filename. so we need to build in some method to check if a file with a particular name already exists and, if so, create a different name. here’s one way :

  set mgFinalPath to mgFolder & mgNewName & "_1" & "." & mgExtension as string
  tell application "Finder"
    set x to 2
    repeat
      set mgExists to exists file mgFinalPath
      if mgExists is true then
        set mgFinalPath to mgFolder & mgNewName & "_" & x & "." & mgExtension as string
        set x to x + 1
      else
        exit repeat
      end if
    end repeat
  end tell

this time we’re appending “_1” to each filename. then the script enters a repeat loop to check if a file with that name already exists. if so, it will change the end to “_2” and then check that, incrementing by one on each pass through the loop. once it reaches a name that has not already been used it exits the repeat loop. this way we don’t lose any files :
screen grab of filenames using final script

this is the final form of the script. it’s always a good idea to test new scripts on duplicate files before implementing them into your workflow — just to make sure they do what you expect (and don’t do what you don’t expect) — you’ve been warned again :

set mgFolder to choose folder
tell application "Finder"
  set mgFiles to items of mgFolder
end tell

repeat with mgFile in mgFiles
  set mgPath to POSIX path of (mgFile as string)
  set mgCreation to creation date of mgFile
  set mgDate to short date string of mgCreation
  set mgTime to time string of mgCreation
  
  set text item delimiters of AppleScript to ":"
  set mgTime to text items of mgTime
  set text item delimiters of AppleScript to "/"
  set mgDate to reverse of text items of mgDate
  set text item delimiters of AppleScript to "."
  set mgExtension to text item -1 of (mgFile as string)
  set text item delimiters of AppleScript to ""
  set mgDate to mgDate as string
  set mgTime to mgTime as string
  set mgTime to text items 1 thru 6 of mgTime as string
  set mgNewName to mgDate & "_" & mgTime
  
  set mgFinalPath to mgFolder & mgNewName & "_1" & "." & mgExtension as string
  tell application "Finder"
    set x to 2
    repeat
      set mgExists to exists file mgFinalPath
      if mgExists is true then
        set mgFinalPath to mgFolder & mgNewName & "_" & x & "." & mgExtension as string
        set x to x + 1
      else
        exit repeat
      end if
    end repeat
  end tell
  
  do shell script "mv -f " & quoted form of POSIX path of mgPath & space & quoted form of POSIX path of mgFinalPath
end repeat

now, of course, you can run this script for any kind of file, not just images. but in its current form it has no error handling for if it encounters a folder. we’ve fixed it so it won’t have a hassle with duplicate files, but if it hits a folder you’ll get something like this :
screen grab of error message if script encounters a folder

dammit you say. but the fix is actually very simple — just change the line “set mgFiles to items of mgFolder” to “set mgFiles to files of mgFolder” and the folders will be skipped — no drama.

but that’s not all …
just to be safe, or because your workflow calls for it — you could change the script so that it makes a copy of the file — giving the new name to the copy and leaving the original untouched.

and again, the solution is very simple — change the shell script from move (mv) to copy (cp) :

do shell script "cp -f " & quoted form of POSIX path of mgPath & space & quoted form of POSIX path of mgFinalPath

you can get a copy of the RenameByDate app here

keep grunting


• related post : renaming finder items : renaming using automator or applescript.
• related post : renaming finder items II : renaming by list.
• related post : renaming finder items IV : easy renaming.

macgrunt icon

InDesign tip : #27

ok, so, here’s the deal with ruler guides … there’s probably handy stuff you don’t know yet …

let’s start with the basics. you click-drag a guide from a ruler (if your rulers aren’t showing, hit cmnd-r). if you want a horizontal guide, drag from the top ruler. if you want a vertical guide, drag from the left ruler. BUT if you accidentally drag from the wrong ruler, just hold your option key before you let that button go and your guide will change orientation. cool.

if you want your guide to only traverse the page, you drop it on the page. if you want it to extend across a complete spread or across the pasteboard, drop it on the pasteboard. simple.

you can also drag a horizontal and vertical guide at the same time — hold your cmnd key and click-drag from your origin (these guides always traverse the spread/pasteboard) :
screen grab of two guides being dragged from origin

to select a guide, just click on it. to select a bunch of guides, click-drag over them. to lock your guides so they can’t be selected (and moved or deleted) go view > grids & guides > lock guides. to lock individual guides (rather than the whole lot) just select and lock them the same as you would an object — object > lock — or cmnd-L.

and you can lock all the guides on a particular layer by double-clicking the layer in the layers panel and then checking the lock guides box in the layer options window that appears (notice you can show/hide guides on a particular layer here too) :
screen grab of the layer options window

an active (selected) guide is the same colour as the active layer. so, if you’re having difficulty seeing a guide as you drag it because the guide is the same colour as the background, just change the colour of the layer or choose a different layer to drag the guide on to.

the colour of a placed (deselected) guide is determined by your ruler guides settings. find this under your layout menu. setting the colour here only affects the guides you create from here-on-in. already existing guides maintain their original colour. change an existing guide by selecting it and then choosing ruler guides (which you can also access with a right-click once a guide is selected). go crazy.

screen grab of document with multiple guide colours

this is also the place to set the view threshold of a guide — that is, the magnification level below which the guide will no longer be visible (unfortunately this isn’t terribly accurate — eg. in CS6, guides with a view threshold of 100% don’t disappear until 55% — you just have to get over it). if you want the guide to be visible at every magnification level — set the view threshold to 5% (the minimum magnification in InDesign) :
screen grab of the ruler guides window

to quickly hide or show all guides use cmnd-; (also see the difference when you just hit ‘w’ — making sure your text cursor isn’t active at the time, of course — this is called preview mode).

to delete all guides on a spread right-click (or cntrl-click) a ruler and choose that command from the dropdown. this can also be accessed through view > grids & guides (this does not affect locked guides) :
screen grab of ruler contextual menu

but you might prefer to do it entirely from the keyboard — select all non-locked guides with cmnd-opt-g and then just hit delete.

to delete all guides throughout an entire document you need a tiny little script which you’ll find all the way back in InDesign scripting : lesson 01

if you just love precision (and don’t we all) you can use your control panel to place and distribute guides exactly where you want them. this screen grab shows what the control panel might look like with four vertical guides selected :
screen grab of control panel with guides selected

and now for tricky guides …
if you double-click the top ruler you’ll get a vertical guide in that position (left ruler gives you a horizontal guide, of course) — this is a great way to get a bunch of guides on the page quickly, before dragging them into exact position.

but the tricky guides are the ones you get if you use this method with the option key selected. they are partially protected guides. you can’t select them with the cmnd-opt-g method and they won’t be deleted when you choose delete all guides on spread. but these guides can still be selected and moved with your mouse and they can be deleted once they are selected. tricky — and handy.

note that the default view threshold of the tricky guides is the same as the magnification level at which they were placed. to change it, simply select the guides and right-click to access the ruler guides window.

but wait, there’s more …
if you want to place a whole bunch of guides in a regular pattern you can use create guides under the layout menu. this not only lets you create the familiar looking columns but also the less common but still-quite-functional-really rows :
screen grab of the create guides window
screen grab of document with guide grid in place
rock on

and there’s still even more …
if you like to work by placing items on a page and then dragging guides to match the edges or centres of your placed items then you really should play around with the AddGuides scripts (both applescript and javascript) that come with InDesign. select your item/s and double-click the script in the scripts panel (window > automation > scripts OR window > utilities > scripts) and you’ll get a dialog box something like this (the javascript version is a little different) :
screen grab of Add Guides script window
automatically placing as many guides for as many objects as you want :
screen grab of artwork after guides have been placed

and we haven’t even started on guide preferences, snap to guides and smart guides — but you probably already know all about that stuff.

keep grunting

macgrunt icon

InDesign scripting : lesson 25

a slug form is a brilliant way to attach proofing data to an InDesign file — especially when you’re trying to keep track of which version of a job a client is signing off on.

there are many variations on the slug form, but all of them need to be filled out at some stage and many of them need to be updated with each new proof. here’s one that can be updated entirely automatically each time a pdf is exported — using applescript (click to enlarge) :
screen grab of a typical slug form

code and job are details pulled from the filename ;
client will be pulled from the document’s filepath ;
size and page are pulled from data for each page ;
proof is incremented by 1 each time the script is run ; and
proof date is gathered using a shell script.

for this example we’ll be using this document in this folder structure :
screen grab showing indesign file in folder hierarchy

the first part of the script starts capturing the data we need :

set mgDate to do shell script "date '+%d/%m/%y'"

tell application id "com.adobe.InDesign"
  tell active document
    set mgPath to file path as string
    set mgName to name
    
  end tell
end tell

the shell script grabs the current date and pulls the elements we want into a text string (mgDate) like this “31/09/12”. that’s the australian date format, if you wanted that weird month-day-year format you’d change it to :

set mgDate to do shell script "date '+%m/%d/%y'"

if you wanted to add the time as well, you could do it like this :

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

which would make mgDate something like “13:45 31/09/12”

we’ve also captured mgPath —
“Macintosh HD:macgrunt:clients:macgrizzle:mg34567_stationery:”
and mgName —
“mg34567_letterhead.indd”
which now have to be broken up to get at their bits. this is done with text item delimiters. a text item delimiter specifies which character is used to separate elements in a text string. in a sentence, the space character is used to separate words. in the file path above, the colon character is used to separate the folder names. so, here’s how we get the bits we need :

    set mgPath to file path as string
    set mgName to name
    set text item delimiters of AppleScript to ":"
    set mgClient to text item 4 of mgPath
    set text item delimiters of AppleScript to "."
    set mgShortName to text item 1 of mgName
    set text item delimiters of AppleScript to "_"
    set mgCode to text item 1 of mgShortName
    set mgJob to text item 2 of mgShortName
    set text item delimiters of AppleScript to "" --(updated from 'default')

this gives us three elements : mgClient = “macgrizzle”, mgCode = “mg34567”, and mgJob = “letterhead” (we’ve also captured mgShortName “mg34567_letterhead” which we could use when we export the PDF).

now, this workflow was created for InDesign files that could have different page sizes throughout and needed a separate slug for each page. so the next part gets placed within a repeat loop to address each page in turn :

    repeat with mgPage from 1 to count pages
      set mgWidth to item 4 of bounds of page mgPage
      set mgWidth to mgWidth as integer
      set mgHeight to item 3 of bounds of page mgPage
      set mgHeight to mgHeight as integer
      set mgDimensions to ((mgWidth as string) & "x" & mgHeight as string) & "mm"

      set active page of layout window 1 to page mgPage
      tell active page of layout window 1
        try -- check to see that correct SLUG is on the page
          set mgFrame to ((text frame 1 of group 1) whose label is "SLUG")
        on error
          try
            set mgFrame to (text frame 1 whose label is "SLUG")
          on error
            display dialog "Your SLUG should be in place on every page." & return & return & "(Note : the correct SLUG has been given a script label to help with automation)"
          end try
        end try
      --bits to enter data into slug table here
      end tell
    end repeat

the first part captures the page number (mgPage) and the page size (mgDimensions). notice that a page does not have a ‘size’, it has bounds and we have to get the dimensions from that. bounds are expressed as a list of four numbers which define, in order, the top, left, bottom and right edges of the page. for an A4 page with mm as the measurement unit, the bounds will be approximately {0.0, 0.0, 297.0, 210.0}. if you’re in the habit of moving your origin, you’ll need to change the way you capture the dimensions which may then be something like {-100.0, -50.0, 197, 160} for example.

the next part checks if there’s a slug on the page (mgFrame). the easiest way to do this is to give the text frame in InDesign a script label. you select the text frame and then choose window > utilities > script label (in CS6 — it might be in a different place in other versions of InDesign) and then type in whatever label you are planning to use. DO NOT hit return/enter, as this will become part of your script label — simply click outside the window instead. script labels are case sensitive :
screen grab of script label window

we check for mgFrame twice — first to see if it’s part of a group (the way the slug was originally set up) and then again in case someone inadvertently ungrouped the slug. this is called error handling — we don’t want the whole script to fail just because the slug is ungrouped.

o … k … now we’ve got all the bits of data we need and we just need to plug them all into the slug. to understand the next bit it helps to know how the slug frame has been created — it’s actually a table with three rows — six cells in the first row, eight cells in the second row and one cell in the third row (again, click to enlarge) :
screen grab of slug showing cell breakdown

we captured the text frame (mgFrame) now we need to address the table within that frame :

        tell table 1 of mgFrame
          set contents of cell 2 of row 1 to mgCode
          set contents of cell 4 of row 1 to mgJob
          set contents of cell 6 of row 1 to mgClient
          set contents of cell 2 of row 2 to mgDimensions
          set contents of cell 4 of row 2 to mgPage as string
          if contents of cell 6 of row 2 is "#" then
            set contents of cell 6 of row 2 to "1"
          else
            set contents of cell 6 of row 2 to (contents of cell 6 of row 2) + 1 as string
          end if
          set contents of cell 8 of row 2 to mgDate
        end tell

hopefully that all makes sense. if not, flick a question through. when it’s done its thing the slug will look something like this :
screen grab of completed slug
bonza.

once that process has been repeated for all the pages it’s time to export the pdf proof. we’re not going to go into all that here — you can see how to export pdfs in lesson 08, lesson 11 and lesson 18

when you’re done cobbling all those bits together you’ll have a script that looks something like this :
screen grab of script in script editor

rippa rita

macgrunt icon