InDesign scripting : lesson 05

let’s revisit a couple of the elements of the script from lesson 04 so you have a better understanding of how they work and how you can integrate them into other scripts. here’s the script again :

Screen grab of Print All Files script

the first thing we’re asking the script to do is place the names of all of InDesign’s current printer presets into a variable which we’ve called mgPresetList. having studied lesson 03 you’ll know that the variable can be called anything you like, as long as it doesn’t clash with standard applescript terminology. mgPresetList is a list of names being generated by InDesign every time the script is run. if printer presets are added or deleted in InDesign, the list will change next time the script is run.

in applescript a list looks like this : {“[Default]”, “A4 landscape”, “A4 portrait”, “A4 landscape (spreads)”, “A3 landscape”, “A3 portrait”, “A3 landscape (spreads)”, “A4 no crops”}. curly braces delineate the start and end of the list, and the elements of the list are contained within double-quotes and separated by commas. if it suited the workflow, we could restrict the list to just the A3 landscape presets by ‘hard-coding’ the list :

set mgPresetList to {"A3 landscape", "A3 landscape (spreads)"}

ok, that’s a quick introduction to lists. we’ll look at other things you can do with lists in future lessons.

next — the choose from list command. this command is an example of a user interface — a way for the script to interact with the user (you) during the running of the script. sometimes user interfaces get input from the user, as in this case. sometimes they merely communicate with the user, as in the display dialog command at the end of the script.

the last part of the choose from list command was explained in lesson 04. let’s look at the first part. the most fundamental example of this command takes the form :

choose from list {SomeList}

our script could have skipped placing the printer preset list into a separate variable like this :

choose from list (name of every printer preset as list)

this is mostly a matter of style. placing data into variables is a good way to keep track of things when you’re starting out. please yourself.

speaking of variables, this is where our second variable comes into play :

set mgPrintPreset to choose from list ...

the mgPrintPreset variable will contain the result of the choose from list command. there are other ways to capture the result of this command, but “set [VariableName] to …” is the easiest.

in the next lesson we’ll look at another important aspect of this script — error handling. so many important elements packed into one simple little script aren’t there?

meanwhile — check out the difference to the second user interface if you delete the second half of the command and just write :

display dialog "ALL DONE!"

macgrunt icon

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s