Oz Creative Pro

January 3, 2006

A little more scripting

I would like to return to scripting InDesign (a favourite topic!). Scripting InDesign is a perfect way to avoid repetitive tasks. A common request from users is a way to print individual pages to PDF or EPS from InDesign. The new InDesign CS2 scripting guide has these useful scripts and far more!

I have recently been showing automation tasks for quick layouts for pages including a javascript for taking XMP Metadata attached to images and using this in a layout. Basically this involves InDesign reading the Metadata for a selected image, taking this and placing it in a text frame and formatting it with an object style automatically formatting the text... nice!

For those interested in playing with this, the script is below. This text can be copied into any text editor and saved as a text file with a file extension .jsx into the Applications > InDesign CS2 > Presets > Scripts folder. To run select and image and double click the script from the scripts palette (Windows > Automation > scripts).

if(app.documents.length != 0){
if(app.selection.length != 0){
if(app.selection[0].graphics.length != 0){
var myFrame = app.selection[0];
var myBounds = myFrame.geometricBounds;
var myX1 = myBounds[1];
var myY1 = myBounds[2];
var myX2 = myBounds[3];
var myY2 = myBounds[2]+10.5;
var myGraphic = app.selection[0].graphics.item(0);
var myLink = myGraphic.itemLink;
var myLinkXMP = myLink.linkXmp;
try{
var myAuthor = myLinkXMP.author;
var myTitle = myLinkXMP.documentTitle;
var myDescription = myLinkXMP.description;
var myTextFrame = myGraphic.parent.parent.textFrames.add(undefined,
undefined, undefined, {geometricBounds:[myY1, myX1, myY2, myX2],
contents:myAuthor + '\r' + myDescription});
myTextFrame.textWrapPreferences.textWrapType = TextWrapTypes.contour;
//this assumes an object style named Picture Caption
myTextFrame.applyObjectStyle(app.activeDocument.objectStyles.item("Picture Caption"), true);
}
catch (myError){
alert("Graphic does not contain the requested XMP information.");
}
}
}
}

Steve

Posted by Stephen Nichols at 3:21 PM on January 3, 2006

Comments

Tuomo Suominen — 7:45 PM on January 10, 2006

Thanks Stephen, this is an excellent script! One question: how would you address the IPTC fields in the standard Adobe XMP panel? I'd need to modify the script to pick up Provider and Source data (from the IPTC Status tab) in order to produce a copyright notice like '©' + Provider + '/' + Source. Best regards, Tuomo Suominen, WSOY, Finland.

Steve Nichols — 7:33 AM on January 12, 2006

Thanks Tuomo, below is a list of the Metadata Properties we currently have access to via scripting. We may have to put a feature request in to access the other Metadata panels :-)

author string -- Document author
class type class [r/o] -- The class descriptor type
copyright info URL string -- Copyright statement URL
copyright notice string -- Copyright text
copyright status unknown/yes/no -- Copyright status of the document
creation date date [r/o] -- Document creation date
creator string [r/o] -- The application that created the document
description string -- Description
document title string -- The document title
format string [r/o] -- The document format
job name string -- Customer-assigned job name
keywords list of string -- Keyword list
modification date date [r/o] -- Document modification date
parent document [r/o] -- The metadata preference's parent
server URL string [r/o] -- Location of the document on asset management server

Regards Steve

Tuomo Suominen — 9:33 PM on January 13, 2006

Thanks for the list! And I did put in a feature request - let's see what happens! Cheers, Tuomo

Fraser Crozier — 5:35 AM on April 15, 2006

I saw a demo of this at IPEX on the Adobe stand, then walked outside and beat my head on the wall after I concantonated the lost savings of not having used such a simple yet powerful tool. Well done. I have designs on how to add to this beautiful thing.

William Wild — 12:50 AM on July 27, 2006

I have copied this as instructed, but can you tell me which IPTC Core fields from Bridge this pull from. I have figured out that myAuthor is "Creator" and myDescription is "Description" but what is MyTitle? And why are the variable not the ones in bridge?

Bill

Anne-Marie — 5:40 AM on October 6, 2006

Is it possible to write a script that will *add* metadata to an InDesign file ... specifically the filenames of linked images?

AM

Steve Nichols — 10:48 AM on October 9, 2006

Hi Anne-Marie

An AppleScript version that does this, goes like:

tell application "Adobe InDesign CS2"
tell document 1
set myfilename to name of link 1
set description of metadata preferences to myfilename
end tell
end tell

Steve

Add your comments

Remember Me?

(You may use HTML tags for style.)