Monday, April 11, 2011

AppleScript identifying InDesign hidden characters

This last week I have been updating a script that acts on Adobe InDesign; the update is to move the script from CS4 to CS5. Besides cleaning up the code to remove the small army of redundant tell statements in the original script, the only edits that it needs to function properly are revisions to the syntax in statements that address script labels. This is a common bug for us this time around and is usually one of the first things I look for, and solves 90% of our broken scripts. This particular script has presented greater difficulty and I am a little stumped. After the standard edits have been made, the script runs to completion, but fails to perform any of the intended actions, and I've narrowed it down to the result of an if statement that never returns true. 

The script is intended to pull the content of all text frames on a page that are tagged with a given script label, and compares the result to a variable for a string match. In this case the control variable is
{"","","",""}
The content of the four text frames on the page is compared to this control in an if statement
if pageData is dataCheck then
 so if all four frames are empty, the if statement should return true, and the contained actions will be executed, which it never does. The culprit appears to be a hidden character that is the remnant of a data merge, but I'm at a loss on how to deal with it.

Record Marker (:)
and End Of Story (#)
Prior to the running of this script, the page is generated by executing a data merge within InDesign onto a template document. The script then checks these particular frames for content because sometimes they receive empty strings of data in the merge. Even so, the hidden characters that InDesign uses to mark the beginning and end of a record entry remain.

Most functions typically ignore these, but it seems that InDesign is picking it up in the get contents command, even though in the context of the application, it has no idea what it is or how to address it. It's taken me a couple days to figure this out.

Here is the native AppleScript Editor event log showing it's script command and the return (lines 1-3):Photobucket
And here is the results of the same command (lines 1-2 above), and the returned list as seen in Script Debugger's event log on AEPrint view:

Photobucket
To translate that into a string view it would look like

{"?","?","?","?"}

AEPrint picks up a bit of data in that string, although it has no idea how to display something that exists only in the context of InDesign as a virtual glyph representing an insertion point. As far as I can tell the character is selectable only through a shift-arrow selection. It can be copy/pasted into into a find/change field but does not return as a result in a text or GREP search.

It is possible to manually remove the record markers from the frame, but this defeats the purpose of using a script as it involves a user touching every affected frame every time a data merge is run. I'd rather not re-write how the script evaluates the content of the frame as the current method is probably the most accurate, but I could attempt to count the characters in the frame and hope that all future merged content is longer than two characters. I need to figure out how to coax AppleScript to allow me to manipulate these hidden-but-existing characters, or otherwise ignore them entirely. Is there an elementary solution here that I'm passing over, making this harder than it should be?

It seems to me, since this script ran well with InDesign CS4, so something might have changed in CS5. Is it possible that hidden characters that were beneath the view of InDesigns other functions are now being included? Or is this an overall bug in the machine?

No comments:

Post a Comment