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.

unfortunately…
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 scripting : lesson 29

the original version of this script was created, like so many scripts, in response to a problem. a necessary third-party export plugin was changing InDesign’s colour settings to a default custom set whenever it was used.

obviously, this is not an ideal situation for a colour-managed workflow and required each user to manually change the settings back every time the plug-in was run. needless to say, sometimes a user forgot to do this.

ordinarily, a script is not going to be of much use in this situation, because the user still needs to remember to run it. but this one takes advantage of yet another handy scripting feature supported by InDesign — the startup script. as you can probably guess, a startup script runs automatically whenever InDesign starts up — not an absolutely perfect solution to this problem, but at least a useful safeguard.

the structure of the script itself is quite simple :

tell application id "com.adobe.InDesign"
  
  set CMS settings of color settings to "macgrunt colour settings"
  
end tell

well, having gone that far, why not also reset a couple of other things, that might be periodically changed during the day, back to your preferred defaults at the start of the next day? this version of the script also resets some display preferences and the workspace :

tell application id "com.adobe.InDesign"
  
  set CMS settings of color settings to "macgrunt colour settings"
  set properties of display settings to {raster:proxy, vector:high resolution, transparency:medium quality}
  
  -----------------------------
  -- thanks to milligramme — adobe forums
  -- http://forums.adobe.com/message/3822734
  do script "app.applyWorkspace('macgrunt');" language javascript
  -----------------------------
  
end tell

that last command is an interesting one. if you look at the scripting dictionary for InDesign, you’ll see there’s an apply workspace command specified for applescript. problem is, it doesn’t work. but, as shown above, it’s possible to call the equivalent javascript using the do script command.

the finished compiled script looks like this :
screen grab of reset settings script

of course, you would need to substitute your own colour settings and workspace names.

well, that’s all very interesting, but how do you make this thing run every time InDesign starts up? rather than the scripts panel folder — just save it using the script file format into this folder :
Applications > Adobe InDesign CS6 > Scripts > startup scripts

what other things could you use a startup script for to help make your day a little easier?

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 28

we’ve already looked a fair bit at how to export pdfs from InDesign using applescript. see lessons 08, 09, 10, 11, and 12 plus InDesign scripting : bringing it together. but these scripts have relied on pdf export presets and, as it turns out, there’s a really good reason NOT to use an export preset when creating a pdf.

presets invariably export a ‘print’ pdf, but these often have tiny white lines criscrossing the screen. this is an unfortunate side effect of transparency flattening and is quite off-putting to clients, who incessantly ask “is it going to print like that?”. but if you export an ‘interactive’ pdf, you don’t get the dreaded white criscrossy lines (strange but true — who knows why?).

now, at this stage, you can’t save interactive pdf settings as export presets. but that don’t matter none — cause we got applescript.

this script is a stripped back version of a much larger one — with additional export options and email generation. this post will focus mainly on the syntax for exporting interactive pdfs — so refer back to the posts listed above if any of the other bits are confusing.

the first part of the script generates a dialog like this :

  set mgDialog to make dialog with properties {name:"How you want this exported then?"}
  tell mgDialog
    tell (make dialog column)
      tell (make border panel)
        tell (make dialog column)
          make static text with properties {static label:"PDF export setting : ", min width:140}
        end tell
        tell (make dialog column)
          set mgResolutionButtons to make radiobutton group
          tell mgResolutionButtons
            make radiobutton control with properties {static label:"72ppi layout", checked state:true}
            make radiobutton control with properties {static label:"96ppi layout", min width:180}
            make radiobutton control with properties {static label:"144ppi layout"}
          end tell
        end tell
      end tell
      tell (make border panel)
        tell (make dialog column)
          make static text with properties {static label:"Document option : ", min width:140}
        end tell
        tell (make dialog column)
          set mgDocumentsButtons to make radiobutton group
          tell mgDocumentsButtons
            make radiobutton control with properties {static label:"active document only", checked state:true}
            make radiobutton control with properties {static label:"all open documents", min width:180}
          end tell
        end tell
      end tell
      
      set mgResult to show mgDialog
      if mgResult is true then
        set mgResolution to selected button of mgResolutionButtons
        set mgDocuments to selected button of mgDocumentsButtons
        destroy mgDialog
      else
        error number -128
      end if
    end tell
  end tell

that gives you a dialog that looks something like this :
screen grab of script dialog

and captures the results into two variables : mgResolution and mgDocuments

it’s important to remember that a radiobutton group returns an integer – starting at 0 – not the label assigned to the selected button. for example, if you select the second option in the top radio button group you will get ’1′ as the result (not “96ppi layout”)

so, the next thing we need to do is assign variables depending on the choices made in the dialog :

  if mgDocuments is 0 then
    set mgDocList to name of active document as list
  else if mgDocuments is 1 then
    set mgDocList to name of every document
  end if
  if mgResolution is 0 then
    set mgResolution to seventy two ppi
  else if mgResolution is 1 then
    set mgResolution to ninety six ppi
  else if mgResolution is 2 then
    set mgResolution to one hundred forty four ppi
  end if
  
  my mgExportInteractive(mgResolution, mgDocList)

you’ll notice here that when re-specifying the variable mgResolution we don’t use quotation marks (it’s seventy two ppi not “seventy two ppi”). this is because the three options shown above are constants defined by the developers. if you want a different resolution you can use an integer between 72 and 300 (eg. set mgResolution to 200).

that last line passes the two final variables (mgResolution and mgDocList) to the subroutine that does the actual work (mgExportInteractive).

now, it’s not really necessary to use subroutines, but they are a great way to make scripts modular. it makes it easy to cut and paste whole chunks of reusable functionality into a future script (and you WILL do this as you get more and more into scripting).

there are two subroutines in this script, the second one is called from within the first one :

on mgExportInteractive(mgResolution, mgDocList)
  tell application id "com.adobe.InDesign"
    set properties of interactive PDF export preferences to {interactive PDF interactive elements option:include all media, generate thumbnails:true, pdf magnification:fit page, pdf page layout:single page, flip pages:false, PDF JPEG quality:maximum, open in full screen:false, page transition override:from document, PDF raster compression:JPEG compression, include structure:false, page range:all pages, export layers:false, export reader spreads:false, view PDF:false}
    set raster resolution of interactive PDF export preferences to mgResolution
    repeat with i from 1 to (count of mgDocList)
      set active document to (every document whose name is item i of mgDocList)
      my mgProcess()
      tell active document
        export format interactive PDF to mgFilePath without showing options
      end tell
    end repeat
  end tell
end mgExportInteractive

on mgProcess()
  tell application id "com.adobe.InDesign"
    set mgFolder to file path of active document
    set mgDocName to name of active document
    set text item delimiters of AppleScript to {"."}
    set mgDocName to text item 1 of mgDocName
    set text item delimiters of AppleScript to ""
    set mgFilePath to mgFolder & mgDocName & ".pdf" as string
  end tell
end mgProcess

now, if you scroll all the way out to the right, you’ll see an interesting thing. oh, all right, you don’t have to scroll all the way out — I’ll tell you — there’s a piece of code there that says “… export reader spreads:false …”. why is this interesting? because, in CS5 (the version this script was written for), exporting reader spreads in an interactive pdf is the default and there’s no option to change it in the standard export dialog box (this has been rectified by CS6). but you CAN change it through applescript — a rare case of something you can do with applescript which cannot be done with the native program. running a script containing that piece of code will change all future exports as well — so you may want to add another line to your final script to reset it back to the default “true” — it’s up to you.

so, that’s the basic syntax for exporting ‘interactive’ pdfs rather than ‘print’ pdfs. check the dictionary for all the other settings you can adjust through applescript.

to download the complete functioning script, you can go here.

have a good one

macgrunt icon

image processing with applescript III

a little while ago we had a look at how to use applescript and sips to scale image files without the hassle of going through photoshop – see image processing with applescript II. open the terminal application, type in “man sips” and you’ll find there’s a whole bunch stuff you can do with images without ever opening photoshop — pretty cool :
screen grab of the sips manual in terminal

… but you can play around with all that another time. today we’re focussing on extending the functionality of the image resize script from that post to make it a little more user friendly. rather than a have script that’s hard-wired to scale images to 500px high, we’ll create one that can accept user input, so that the pixel dimensions can be changed each time the script is run.

to do that we need to first create a dialog. unfortunately the dialog possibilities with standard applescript are pretty crap — particularly when compared to all the options available to applescript dialogs in InDesign – border panels, columns, rows, checkbox controls, dropdowns, enabling groups, event listeners, comboboxes, editboxes, radiobuttons, etc.

here is all you get with standard dialogs :
screen grab of dialog entry in standard additions dictionary

well, although that’s pretty diabolical, it’s still enough for what we need. here’s the first part of the script :

display dialog "enter the pixel ratio you want these scaled to" with title "resize images" default answer "800" buttons {"cancel", "wide", "high"} default button 1
set mgResult to result
set mgText to text returned of mgResult
set mgButton to button returned of mgResult

that’ll give us a dialog something like this :
screen grab of resize images script dialog

… which gives us two pieces of information — the text entered and the button clicked – both captured into variables. if you want to make the script fool-proof, you’ll need to add some error handling to ensure that the text entered is an integer. but in its current form, the script assumes that the user is not an idiot.

the next part of the script creates a subfolder in the finder to save the transformed images into (this script creates duplicates of the original images rather than overwriting the originals with the resized versions) – then creates a reference to that folder for use later in the script :

set mgFolder to (mgText & "px") as string

tell application "Finder"
  set mgItems to selection
  set mgContainer to container of item 1 of mgItems
  set mgContainer to mgContainer as alias
  if (exists folder mgFolder of folder mgContainer) is false then
    make folder at mgContainer with properties {name:mgFolder}
  end if
end tell

set mgFinalFolder to mgContainer & mgFolder & ":" as string

then comes the key to the adaptability of this script — altering the final sips command based on the user’s choices in the dialog. we capture this into a variable called mgScriptString :

if mgButton is "high" then
  set mgScriptString to "sips --resampleHeight '" & mgText & "' "
else
  if mgButton is "wide" then
    set mgScriptString to "sips --resampleWidth '" & mgText & "' "
  end if
end if

the rest of the script is pretty much as per the previous post except that we insert the mgScriptString variable into the do shell script command :

repeat with mgItem in mgItems
  set mgName to name of mgItem
  set mgFinalpath to mgFinalFolder & mgName
  set mgPath to POSIX path of (mgItem as text)
  
  --convert mgFinalpath to POSIX form
  set text item delimiters to ":"
  set mgFinalpath to text items 2 thru -1 of mgFinalpath
  set text item delimiters to "/"
  set mgFinalpath to mgFinalpath as string
  set text item delimiters to ""
  
  set mgFinalpath to quoted form of mgFinalpath
  
  try
    do shell script mgScriptString & quoted form of POSIX path of mgPath & " --out " & mgFinalpath
    do shell script "sips -m '/System/Library/ColorSync/Profiles/sRGB Profile.icc' -i " & mgFinalpath
  end try
end repeat

wrap all that in an open handler (and delete the line “set mgItems to selection”) and you’ll have a script that looks like this :
screen grab of finished script

save that as an application and whack it in your sidebar. drag and drop as many images as you like onto the app — they’ll all be scaled quicker than you could do it through photoshop. don’t worry about accidentally dropping non-image files — these just get skipped.

you can also go here to get the complete image processing script.

have a good one

macgrunt icon