InDesign scripting : lesson 23

here’s a quickie based on a question over at the InDesignSecrets forum. how do you centre the page without changing your zoom level?

there are a few different ways to centre a page :
cmnd-0 = fit page
cmnd-opt-0 = fit spread
cmnd-opt-shift-0 = fit pasteboard
but all of these change your zoom level.

applescript is perfect for this kind of problem — you’ve got something that you want to do time and time again, but it’s not available in the standard package. as with most scripting solutions, you need to be a little bit cunning — if there was a ‘centre page’ command, it would be available in InDesign, but there’s not, so you have use a combination of other commands to get what you want.

for this lesson we’re using CS2, but it’s pretty much the same for other versions. let’s look at the dictionary — search for ‘zoom’ :
screen grab of CS2 dictionary showing zoom command
(click the image to get a clearer view) there’s a whole bunch of entries relating to interactive elements — probably not much use to us. there’s also a ‘zoom’ command — which, you can see, matches up with our zooming options directly in InDesign (view menu). there’s one other dictionary entry for zoom — zoom percentage — let’s check that out :
screen grab of CS2 dictionary showing zoom percentage property
bingo! here we see that the current zoom percentage is a property of the layout window. SO, all we need to do is capture that percentage, then centre the page, then reset the layout window to the correct percentage :

tell application "Adobe InDesign CS2"
  tell layout window 1 of document 1
    set theZoom to zoom percentage
    zoom given show pasteboard
    set zoom percentage to theZoom
  end tell
end tell

awesome — works perfectly… UNLESS you have something selected — then, as you know, InDesign’s default behaviour is to centre on the selection. now, if that’s what you want it to do, no problem. but the original spec was to centre the page. SO, first we need to drop the selection :

tell application "Adobe InDesign CS2"
  tell layout window 1 of document 1
    select nothing
    set theZoom to zoom percentage
    zoom given show pasteboard
    set zoom percentage to theZoom
  end tell
end tell

awesome — again.

just save whichever version works for you into your scripts panel folder. if you don’t know how to do that — go right back and have a look at InDesign scripting : lesson 01. remember to update the first line to your version of InDesign.

then, to complete the awesomeness, assign your preferred keyboard shortcut to activate the script. if you don’t know how to set your own keyboard shortcuts, you need InDesign tip : #06.

and now for your homework…
how would you change the script so that it centred on the page, but still maintained the selection?

macgrunt icon

thoughtful and respectful comments welcome

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s