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

Advertisements

InDesign tip : #14

as with most InDesign features, zooming can be done in myriad ways. here are just a few.

obviously there’s the magnifying glass tool which you can click on in your tool panel or, if you want to be tricky, hit ‘z’. with the magnifying tool you just click to zoom in by increments or click-drag to select an area to zoom in on. and you hold down the option key if you want to zoom out.

but there’s really no need to change to that tool when you can activate it temporarily by holding down command-space (or command-option-space for the zoom-out tool). unfortunately apple commandeered this shortcut for spotlight (which I believe was just pure bloody-mindedness). but you can change the spotlight shortcut through system preferences (or, indeed, change the InDesign shortcut through edit > keyboard shortcuts).

there’s a whole bunch of other keyboard shortcuts :
cmnd-+ = zoom in
cmnd- = zoom out
cmnd-0 = fit page
cmnd-opt-0 = fit spread
cmnd-opt-shift-0 = fit pasteboard
cmnd-5 = zoom to 50%
cmnd-1 = zoom to 100%
cmnd-2 = zoom to 200%
cmnd-4 = zoom to 400%

you can also use cmnd-opt-5 to quickly access the magnification dropdown menu : use your up and down arrows to zoom in and out ; or type in the percentage you want.

check out how zooming with these shortcuts differs depending on whether or not you have anything selected.

but that’s not all…
integral to zooming around the page is the hand tool — to drag another area into view when you’re zoomed in. again, there is no reason to change to this tool. in most instances you can temporarily access this tool by holding down the spacebar. the only time this doesn’t work is when the text tool is selected (for obvious reasons). if it is active in a selected text frame then you have to use the option key — if no text frame is selected you have to use option-space (go figure).

macgrunt icon