InDesign scripting : lesson 01

you’d be surprised at how much time you can save in your day-to-day work by learning the basics of a scripting language — to automate the monkey-work. in the same way that keyboard shortcuts speed up your workflow, applescript takes the tedium out of repetitive tasks.

the encouraging thing about learning applescript is that the language is familiar. often you can see immediately what a command is going to do — even with no prior scripting experience :

tell application "Adobe Indesign CS4"
    save every document
    close every document
end tell

the discouraging thing about learning applescript is that the syntax is often tortured and frustratingly difficult to get right. this example does exactly the same as the one above :

tell application "Adobe Indesign CS4" to close every document saving yes

encouraging : applescript phrasing is very flexible. here are two more examples giving the same result as above :

tell every document of application "Adobe InDesign CS4"
end tell
save every document of application "Adobe InDesign CS4"
close every document of application "Adobe InDesign CS4"

discouraging : it’s not always obvious what will work and what will not. this one fails :

tell application "Adobe InDesign CS4"
  save and close every document
end tell

but by far the best thing about learning applescript is that there is absolutely no capital outlay. if you have a mac (one that’s less than twenty years old, that is), you have all you need to get started. you’ll find the necessary software here : applications > applescript > script editor OR, in later versions of OSX applications > utilities > applescript editor.

to create your first script
first go to InDesign and open the scripts panel : window > automation > scripts OR window > utilities > scripts. you’ll most likely see a list of pre-installed scripts to experiment with (scripts are activated by double-clicking them). select one of these and choose “reveal in finder” from the panel’s dropdown menu. this will show you where you need to save scripts to make them available to InDesign.
for CS2 : Applications > Adobe InDesign CS2 > Presets > Scripts >
for CS4 : Applications > Adobe InDesign CS4 > Scripts > Scripts Panel >

next, copy the first example above into script editor — ensuring you change the InDesign version number as appropriate. hit the ‘compile’ button to confirm that all is ok. if it fails to compile you may need to retype the two ” characters. if you like, you could also take it for a test run by hitting the … you got it … ‘run’ button.

finally, save the finished script in the relevant location, choosing the script file format (.scpt). DO NOT check the “run only” box — this is only for distributing scripts in a format which does not allow another user to open it and see how it’s done — like the iQuit app. if you check “run only” you’ll never be able to edit that script again.

congratulations you’ve just created a script that will do in a double-click what once required two double-handed keyboard shortcuts (command-option-shift-s then command-option-shift-w, for those who weren’t aware). if you saved it in the right place, it will appear immediately in your InDesign scripts panel.

but wait, there’s more …
this one comes in handy for large documents that have got a bit out of control in the guides department. yes, it will do exactly what it says, for the whole document.

tell application "Adobe InDesign CS4"
  tell active document
    delete guides
  end tell
end tell

if you haven’t seen it yet, watch postcards — an animation showing a more complex applescript workflow in action.

macgrunt icon

thoughtful and respectful comments welcome

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

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

Facebook photo

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

Connecting to %s