a slug form is a brilliant way to attach proofing data to an InDesign file — especially when you’re trying to keep track of which version of a job a client is signing off on.
there are many variations on the slug form, but all of them need to be filled out at some stage and many of them need to be updated with each new proof. here’s one that can be updated entirely automatically each time a pdf is exported — using applescript (click to enlarge) :

code and job are details pulled from the filename ;
client will be pulled from the document’s filepath ;
size and page are pulled from data for each page ;
proof is incremented by 1 each time the script is run ; and
proof date is gathered using a shell script.
for this example we’ll be using this document in this folder structure :

the first part of the script starts capturing the data we need :
set mgDate to do shell script "date '+%d/%m/%y'"
tell application id "com.adobe.InDesign"
tell active document
set mgPath to file path as string
set mgName to name
end tell
end tell
the shell script grabs the current date and pulls the elements we want into a text string (mgDate) like this “31/09/12″. that’s the australian date format, if you wanted that weird month-day-year format you’d change it to :
set mgDate to do shell script "date '+%m/%d/%y'"
if you wanted to add the time as well, you could do it like this :
set mgDate to do shell script "date '+%H:%M %d/%m/%y'"
which would make mgDate something like “13:45 31/09/12″
we’ve also captured mgPath —
“Macintosh HD:macgrunt:clients:macgrizzle:mg34567_stationery:”
and mgName —
“mg34567_letterhead.indd”
which now have to be broken up to get at their bits. this is done with text item delimiters. a text item delimiter specifies which character is used to separate elements in a text string. in a sentence, the space character is used to separate words. in the file path above, the colon character is used to separate the folder names. so, here’s how we get the bits we need :
set mgPath to file path as string
set mgName to name
set text item delimiters of AppleScript to ":"
set mgClient to text item 4 of mgPath
set text item delimiters of AppleScript to "."
set mgShortName to text item 1 of mgName
set text item delimiters of AppleScript to "_"
set mgCode to text item 1 of mgShortName
set mgJob to text item 2 of mgShortName
set text item delimiters of AppleScript to default
this gives us three elements : mgClient = “macgrizzle”, mgCode = “mg34567″, and mgJob = “letterhead” (we’ve also captured mgShortName “mg34567_letterhead” which we could use when we export the PDF).
now, this workflow was created for InDesign files that could have different page sizes throughout and needed a separate slug for each page. so the next part gets placed within a repeat loop to address each page in turn :
repeat with mgPage from 1 to count pages
set mgWidth to item 4 of bounds of page mgPage
set mgWidth to mgWidth as integer
set mgHeight to item 3 of bounds of page mgPage
set mgHeight to mgHeight as integer
set mgDimensions to ((mgWidth as string) & "x" & mgHeight as string) & "mm"
set active page of layout window 1 to page mgPage
tell active page of layout window 1
try -- check to see that correct SLUG is on the page
set mgFrame to ((text frame 1 of group 1) whose label is "SLUG")
on error
try
set mgFrame to (text frame 1 whose label is "SLUG")
on error
display dialog "Your SLUG should be in place on every page." & return & return & "(Note : the correct SLUG has been given a script label to help with automation)"
end try
end try
--bits to enter data into slug table here
end tell
end repeat
the first part captures the page number (mgPage) and the page size (mgDimensions). notice that a page does not have a ‘size’, it has bounds and we have to get the dimensions from that. bounds are expressed as a list of four numbers which define, in order, the top, left, bottom and right edges of the page. for an A4 page with mm as the measurement unit, the bounds will be approximately {0.0, 0.0, 297.0, 210.0}. if you’re in the habit of moving your origin, you’ll need to change the way you capture the dimensions which may then be something like {-100.0, -50.0, 197, 160} for example.
the next part checks if there’s a slug on the page (mgFrame). the easiest way to do this is to give the text frame in InDesign a script label. you select the text frame and then choose window > utilities > script label (in CS6 — it might be in a different place in other versions of InDesign) and then type in whatever label you are planning to use. DO NOT hit return/enter, as this will become part of your script label — simply click outside the window instead. script labels are case sensitive :

we check for mgFrame twice — first to see if it’s part of a group (the way the slug was originally set up) and then again in case someone inadvertently ungrouped the slug. this is called error handling — we don’t want the whole script to fail just because the slug is ungrouped.
o … k … now we’ve got all the bits of data we need and we just need to plug them all into the slug. to understand the next bit it helps to know how the slug frame has been created — it’s actually a table with three rows — six cells in the first row, eight cells in the second row and one cell in the third row (again, click to enlarge) :

we captured the text frame (mgFrame) now we need to address the table within that frame :
tell table 1 of mgFrame
set contents of cell 2 of row 1 to mgCode
set contents of cell 4 of row 1 to mgJob
set contents of cell 6 of row 1 to mgClient
set contents of cell 2 of row 2 to mgDimensions
set contents of cell 4 of row 2 to mgPage as string
if contents of cell 6 of row 2 is "#" then
set contents of cell 6 of row 2 to "1"
else
set contents of cell 6 of row 2 to (contents of cell 6 of row 2) + 1 as string
end if
set contents of cell 8 of row 2 to mgDate
end tell
hopefully that all makes sense. if not, flick a question through. when it’s done its thing the slug will look something like this :

bonza.
once that process has been repeated for all the pages it’s time to export the pdf proof. we’re not going to go into all that here — you can see how to export pdfs in lesson 08, lesson 11 and lesson 18
when you’re done cobbling all those bits together you’ll have a script that looks something like this :

rippa rita

I put it together and it seems correct –
But I can’t get text item 2 of ” ” – number -1728
Renamed document & moved to desktop etc.. keep getting same error.
_____________
tell current application
do shell script “date ‘+%H:%M %d/%m/%y’”
–> “07:47 02/10/12″
end tell
tell application “Adobe InDesign CS6″
get file path of active document
–> file “jobvol: TOM:208573 Polaris BC: Layouts:”
get name of active document
–> “208573 Polaris Proofs.indd”
Result:
error “Can’t get text item 2 of \”208573 Polaris Proofs\”.” number -1728 from text item 2 of “208573 Polaris Proofs”
_____________
Thank You for sharing all of this useful information with us!
G’day Tom
You need to select the text item delimiter that is appropriate to your workflow.
The code to separate the bits of filename in the post is :
which separates the filename “mg34567_letterhead.indd” into :
mgShortName – mg34567_letterhead
mgCode – mg34567
mgJob – letterhead
But your filename does not have any underscores. So using the above code you’ll get :
mgShortName – 208573 Polaris Proofs
mgCode – 208573 Polaris Proofs
mgJob – {error}
Since your filenames only have spaces, this is the code you need :
The first line starting “set mgJob…” will give you this — {“Polaris”, “Proofs”} — a list of items
The second line starting “set mgJob…” will give you this — “Polaris Proofs” — the list items in a string separated by whatever the current text item delimiter is.
See the difference to mgJob with these two variations :
Hope that makes things a bit clearer
Good luck with it
m.
Reblogged this on Sutoprise Avenue, A SutoCom Source.
Hi macgrunt,
I am getting the following error message:
AppleScript Error!
Error Number” -1708
Error String: every page of doesn’t understand the count message.
Engine: Default
File:/Applications/Adobe Indesign CS6/Scripts/Scripts Panel/Samples/AppleScript/Slug.applescript
Do you know of any possible fixes as scripting is beyond my capabilities?
Thanks
g’day
my initial suggestion would be to ensure you have copied the script across accurately.
the script is failing on this line (or the line that should say) :
repeat with mgPage from 1 to count pagesi’ll flick you the complete script — see if you still have the same issue.
m.