… a short interlude …

it’s time for a short break — after fifty posts in twenty eight weeks.

it was said in days of old that macgrunt is all about workflow automation and optimisation. but macgrunt is also about rest and relaxation — and verily so.

thanks for reading, hope you’re finding this stuff useful — normal transmission will be resumed as soon as possible.

if you haven’t seen it yet — have a chuckle with the very first macgrunt post — iQuit

macgrunt icon

InDesign scripting : lesson 17

here’s a quickie that’s really handy for those of you who have to (against your will, obviously) allow other users to access your InDesign files.

this script was created for a publishing workflow where the editors did their thing right in the live files. this meant there was the potential for page elements to be inadvertently moved or resized or whatever. by locking everything in a document we gain peace of mind for both the editors and designers — editors can do their editing, but there’s no danger that they’ll alter the frames themselves.

to start, we need a dialog box so the user can choose to either lock or unlock everything. as always, follow along in applescript editor (found in applications > utilities) or, for older OS versions, script editor (found in applications > applescript) and update the script to your version of InDesign :

tell application "Adobe InDesign CS4"
  activate
  set mgDialog to make dialog with properties {name:"Groovy script to either Lock or Unlock everything in a document"}
  tell mgDialog
    tell (make dialog column)
      tell (make border panel)
        tell (make dialog column)
          make static text with properties {static label:"What do you want to do?    "}
        end tell
        tell (make dialog column)
          set mgLockButtons to make radiobutton group
          tell mgLockButtons
            make radiobutton control with properties {static label:"Lock everything", checked state:true}
            make radiobutton control with properties {static label:"Unlock everything"}
          end tell
        end tell
      end tell
      
      set mgResult to show mgDialog
      if mgResult is true then
        set mgLock to selected button of mgLockButtons
        destroy mgDialog
      else
        display dialog "OK, fine, see if I care" buttons {"Cancel"} default button 1
      end if
      if mgLock is 0 then
        my mgLockAll()
      else if mgLock is 1 then
        my mgUnlockAll()
      end if
    end tell
  end tell
end tell

massive macgrunt fans will understand pretty much all of that because they have paid attention and studied hard throughout all the previous lessons.

the first part creates a nice looking dialog box for our discerning user :
screen grab of dialog box created by Lock/Unlock script

the second part captures the results of the dialog and acts accordingly — either activating one of two subroutines or, just for shits and giggles, displaying a friendly message if the user decides to cancel instead :
screen grab of Lock/Unlock script  message if user cancels

unusually, the rest is very simple — these two subroutines just get placed after the last ‘end tell’ :

on mgLockAll()
  tell application "Adobe InDesign CS4"
    tell active document
      set locked of every page item to true
      set locked of every guide to true
    end tell
    display dialog "All items are now locked" & return & return & "" buttons {"Rock On!"} default button 1 giving up after 1
  end tell
end mgLockAll

on mgUnlockAll()
  tell application "Adobe InDesign CS4"
    tell active document
      set locked of every page item to false
      set locked of every guide to false
    end tell
    display dialog "All items are now unlocked" & return & return & "" buttons {"Bonza!"} default button 1 giving up after 1
  end tell
end mgUnlockAll

now, applescript experts will be able to streamline that script so that it only takes up about half as many lines — but who cares? it works so fast and effectively that it really doesn’t matter.

macgrunt icon

InDesign tip : #15

working with text in InDesign doesn’t have to be difficult. here are just a few text selection tricks.

1x click = place cursor
2x click = select word
3x click = select line
4x click = select paragraph
5x click = select entire story
…but you probably already knew that.

to select a specific portion of text — click once at the beginning of the bit you want to select (to place your cursor) and then shift-click at the end — everything in between gets selected.

you can also navigate around and select text entirely with your keyboard.
left and right arrows take you along a line one character at a time — but hold down the command key and you’ll jump by words.
similarly, the up and down arrows move between lines of text — add the command key and you’ll jump to the beginning of the next paragraph.

here are some other tricks with the arrow keys
shift-left selects the next character
shift-command-left selects the next word
shift-down selects the next line
shift-command-down selects to the end of the paragraph
…these also work with the up and right arrows

combine all that with keyboard shortcuts for your paragraph and character styles and you’ll be a text formatting wiz.

macgrunt icon

InDesign scripting : lesson 16

this is the fourth of a series of lessons about how to script the contents of documents. so far we’ve looked at how to create and do things with page items. now let’s have a closer look at colours.

if you want to follow along — open a new document. then run this script from script editor (found in applications > applescript) — as always, update the script to your version of InDesign :

tell application "Adobe InDesign CS4"
  activate
  tell active document
    make rectangle with properties {fill color:"Black", geometric bounds:{5, 5, 10, 10}}
    make rectangle with properties {fill color:swatch 2, geometric bounds:{10, 10, 15, 15}}
    make rectangle with properties {fill color:"C=50 M=100 Y=0 K=10", geometric bounds:{15, 15, 20, 20}}
  end tell
end tell

now, it’s more than likely that the script will fail on that third rectangle. and this is the frustrating thing about colours — you can’t use a colour unless it already exists as a swatch. but more about that in a moment.

the script above shows two ways to reference a colour : by name or by index (ie. position in the swatches panel). note that if you had a swatch called ‘swatch 2’ you’d reference that with double quotes (… fill color:”swatch 2″ …) but you’d NEVER name a swatch that would you!? the other thing to note is that when the rectangle is first drawn it will have whatever fill and stroke attributes are set as defaults — exactly the same as if it were drawn using the rectangle tool (not to be confused with the rectangle frame tool).

ok. to get around the missing colour issue you have to create a new swatch. notice that you don’t actually make a new swatch, you make a new colour — which just happens to appear in your swatches panel (confusing? you bet) :

tell application "Adobe InDesign CS4"
  activate
  tell active document
    make color with properties {model:process, space:CMYK, color value:{50, 100, 0, 10}, name:"C=50 M=100 Y=0 K=10"}
    make color with properties {model:process, space:RGB, color value:{250, 255, 0}, name:"R=150 G=255 B=0"}
    make rectangle with properties {fill color:"Black", geometric bounds:{5, 5, 10, 10}}
    make rectangle with properties {fill color:swatch 2, geometric bounds:{10, 10, 15, 15}}
    make rectangle with properties {fill color:"C=50 M=100 Y=0 K=10", geometric bounds:{15, 15, 20, 20}}
    make rectangle with properties {fill color:"R=250 G=255 B=0", geometric bounds:{20, 20, 25, 25}}
  end tell
end tell

note : you should always specify the name — you can leave this out but you may get swatches with incorrect names (this happens if the “Name with Color Value” check box was not selected the previous time a swatch was created). the naming convention used here is a good one to follow in InDesign generally (not only when scripting) it saves confusion with duplicate or near-duplicate swatches. calling a swatch “purplish” is just going to lead to tears somewhere down the line.

now, if you try to run that script again on the same file it will fail because you cannot make a colour if it already exists — that is, you cannot have two colours with the same name. this next snippet will work because each swatch has a different name :

tell application "Adobe InDesign CS4"
  activate
  tell active document
    make color with properties {model:process, space:CMYK, color value:{50, 100, 0, 10}, name:"Blue"}
    make color with properties {model:process, space:CMYK, color value:{50, 100, 0, 10}, name:"Another Blue"}
    make color with properties {model:process, space:CMYK, color value:{50, 100, 0, 10}, name:"Yet Another Blue"}
  end tell
end tell

but that would be just silly. however, it does highlight why you should get into good swatch naming habits.

there are a few ways to get around the problem of the previous script failing — here’s a simple one :

tell application "Adobe InDesign CS4"
  activate
  tell active document
    try
      make color with properties {model:process, space:CMYK, color value:{50, 100, 0, 10}, name:"C=50 M=100 Y=0 K=10"}
    end try
    try
      make color with properties {model:process, space:RGB, color value:{250, 255, 0}, name:"R=150 G=255 B=0"}
    end try
    make rectangle with properties {fill color:"Black", geometric bounds:{5, 5, 10, 10}}
    make rectangle with properties {fill color:swatch 2, geometric bounds:{10, 10, 15, 15}}
    make rectangle with properties {fill color:"C=50 M=100 Y=0 K=10", geometric bounds:{15, 15, 20, 20}}
    make rectangle with properties {fill color:"R=250 G=255 B=0", geometric bounds:{20, 20, 25, 25}}
  end tell
end tell

try blocks are great. if the script CAN do the task it does — if it can’t, it just moves on to the next command.

well, that’s a quick and dirty introduction to colours. what’s up next? who knows. til then — keep grunting.

macgrunt icon

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