Given:
An Indesign CS6 document consisting of one page and one empty text frame with scriptlabel VarData.
There is a text file with 5 columns linked to this document. 5 header names visible in the merge data panel. 01-REF 02-REF 03-REF 04-REF 05-REF
Manually you would drag the headers in the text frame, like below
<<01-REF>>
<<02-REF>>
<<03-REF>>
<<04-REF>> <<05-REF>>
Than it is not text, but placeholders for data merge.
I would like to fill the text frame with the placeholders with applescript.
When you replace the contents with the above text, it is just text and it doesn’t have the data merge abilities.
I have tried the code below
tell application "Adobe InDesign CS6"
tell document 1
set X to data merge field 5 of data merge properties
set VarDataFrame to the first text frame whose label is "VarData"
set theStory to parent story of contents of VarDataFrame
set contents of VarDataFrame to field name of X -- this results only in text
set contents of VarDataFrame to X -- this gives an error
end tell
end tell
In my editor I can see that the variable X contains now
field name: “05-REF”
class: data merge field
field type: text field
index: 5
But I can’t find the right syntax to place the placeholder <<05-REF>> in a way that it is a working placeholder instead of normal text
Can someone help me to achieve this?
It has something to do with data merge field or data merge text placeholder
Hi. Using the data merge panel in the manner you’ve requested is generally inadvisable, as it’s a poor use of InDesign’s AppleScript functionality, being a “dumb” automation method in its own right. You’d have much finer control with access to text/image features by using the script label as a target. That said, this directly answers your question:
tell application "Adobe InDesign CS3"'s document 1
make data merge text placeholder with properties {parent story:story 1, story offset:0, field:(data merge 1's data merge field 1 whose field name = "_05-REF_")} --assumes merge data source is loaded
end tell
This script is a part of a larger one which is reading the first line of a csv file as the header list.
In the example I have made now, I’ve placed is as een property for demo reasons
property csvHeaderList : {"_01-REF_", "_02-REF_", "_03-REF_", "_04-REF_", "_05-REF_"}
tell application "Adobe InDesign CS6"'s document 1
set CountOfHeaders to count of items in csvHeaderList
set VarDataFrame to the first text frame whose label is "VarData"
set ParentStoryID to get the parent story of VarDataFrame
set text 1 of ParentStoryID to ""
set InsertionPoint to 0
repeat with H from 1 to CountOfHeaders
set CurrentHeader to item H of csvHeaderList
make data merge text placeholder with properties {parent story:ParentStoryID, story offset:InsertionPoint, field:((data merge 1's data merge field 1 whose field name = CurrentHeader))}
set InsertionPoint to count of characters of VarDataFrame
end repeat
end tell
Now I only have to figure out how to enter additional text, comma’s, spaces or carriage returns between the fields to make it look better.