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"
  save
  close
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 >
etc.

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

video 01 : postcards

macgrunt is all about workflow optimisation, with an emphasis on automation, particularly applescript. in a few days you’ll see the first InDesign scripting lesson. these lessons are intended to get you up and running — even if you’ve never contemplated scripting previously.

why should you bother with this rubbish?

postcards is a quick animation which shows an actual script performing a real-life task in a fraction of the time it would take a real-life human. the animation is built from screen grabs from the actual workflow — so that dialog box at the end showing how long the script took to do the job is real and accurate (testing was done with CS2 on a G5 PowerPC running OSX 10.5.7).

if that doesn’t convince you to start learning, stay tuned, more to follow.

macgrunt icon

InDesign tip : #01

most of the indesign tips that appear here will be focussed on increasing productivity. but, for now, let’s start with a bit of frivolousness. this works in CS4.

go to InDesign menu > about InDesign
then type ‘butterfly’
– click to pin and unpin butterflies
– option-click to shoot them down
– return to quit

… hours of fun for all the family

thanks to Iain Anderson : funwithstuff

macgrunt icon

mounting servers

applescript is a great way to automate repetitive and tedious tasks. you can find an applescript solution for connecting to smb (or afp) servers here. however, if connecting to servers is the only thing you want the workflow to do, it’s just as easy, if not easier, to use automator. here’s one way.

first open the automator application and drag these two actions into the workspace : get specified finder items and open finder items (it’s easy to find an automator action by typing just a few letters into the search field).

next, create aliases of your servers in an appropriate place (you can usually do this by simply dragging the volume into a folder — you may need to hold down command-option as you click and drag). then drag the aliases into the get specified finder items window in your automator workflow.

save it as an application and you’re done. then you just need to decide where you’re going to launch it from. the dock is handy for this one.

mount servers at login …
if you prefer to automatically mount the servers at startup, you can add the app to your login items (system preferences > accounts > login items — click the ‘+’ button and navigate to where you saved the app). NOTE: if you are going to launch at startup, you may need to add a pause to the beginning of the workflow to allow other services to finish starting up first. if your mac tries to connect to the servers too soon, you’ll get an error.

macgrunt icon

finder cleanup

ever find yourself with a shitload of windows open in the finder and all you really want to do is get back to the one (or more) folders that you use the most? of course you have. here’s a groovy little app that will restore your finder to a predefined setup you choose yourself.

you can go here to get the FinderCleanup app

after downloading, drag the app to your preferred launch location. you may find the toolbar is most appropriate for this one.


next, set your finder windows exactly as you want them to appear by default. the example below shows a larger window, in column view, pointing to the user folder and a smaller window, in list view, pointing to the documents folder. you can set as many windows as you like.

now you’re ready to click the app. the first time you run it you’ll get this message — reminding you to set things up the way you want them before continuing. every time you run FinderCleanup after that, it will simply reset your finder to your chosen setup.

for those interested in this sort of thing…
this script demonstrates the handiest feature of the script property — persistence. if you open FinderCleanup in the Script Editor application you’ll see a property declared at the start of the script — property mgProps : “”
mgProps begins life as an empty variable, but gets populated with all the data necessary to replicate your chosen finder setup the first time the app is run. this data persists after the app is run. that is, the data is saved as an integral part of the app.

what if you change your mind?
if you change your mind and want different windows opened by default, simply open FinderCleanup in the Script Editor application, click the compile button, save and close. this resets mgProps to an empty property and the app will behave as though you’re running it for the first time.

but wait, there’s more…
You may also be interested in this nice little applescript from Nik’s Crappy Blog to pack away all your desktop clutter hide-and-restore-desktop-icons.

macgrunt icon