scripting indesign data merge

I’m trying to select a source csv file and merge it into an Indesign document. I don’t understand the Indesign data merge applescript dictionary. It is a simple operation in real time, pull down automator menu and select data merge. It gives you an option palette to select the source document. Set a few preferences like create documents for a range of records. Then there is the option create merged document. But in applescript it is a whale of another color. The following script is what I want it to do but I can’t figure out how to name all of the objects, and references. I already have the placeholder fields in my document so while it is open and I call data merge it should just import the data into the right text boxes.

There aren’t really any commands except in the preferences. I can’t understand even how to call the data merge. The select data source command is a
command of the data merge preferences. The data merge is a class of the preferences suite. The data source file is a property of the data merge preferences. The data merge options are a class of the preferences suite and a property of the basics suite. This doesn’t tell me very much.

Any ideas, encouragement, or direction on where to go. Would this be easier in applescript studio?

tell application “Adobe InDesign CS2”
data merge option
select data source “Mac OS X:Users:jrough:desktop:mergeRecordsDoc”
data merge option set parent document = active document
set record number preference to record number = 1
data merge option create new document = t
end tell
:frowning:

Browser: Firefox 1.5.0.4
Operating System: Mac OS X (10.4)

jrough,

I have been trying to do the same thing all day. I came across your post while looking up information about it using Google.
I have finally found an answer! I’m not sure how to explain it, but hopefully after dissecting it a bit you will understand. Basically you have to have a document open (preferably an InDesign template file) that has already been tagged with data merge fields matching those in the .csv file you wish to merge with it. When you run this short example script, it will ask you to locate the .csv file you wish to merge. It then takes that file and uses the “select data source” command from the Preferences Suite of the InDesign AppleScript library and tells it to use “data source file thisDataSource” where “thisDataSource” is the path to the .csv file selected (as an alias or string). Next it tells InDesign to “merge records” of “thisDataMerge” which is the first (if not only) data merge of “thisDocument” which should be the frontmost document in InDesign. This “merge records” command does the same thing as the “create merged documents” command from the data merge palette in InDesign.

tell application "Adobe InDesign CS2"
	set thisDocument to the front document
	set thisDataMerge to data merge 1 of thisDocument
	set thisDataSource to choose file without invisibles
	select data source of thisDataMerge data source file thisDataSource
	merge records thisDataMerge
end tell

Instead of having the template document already open, you could have it set the variable “thisDocument” to another “choose file” prompt.

Happy coding!

Dallas