Thursday, April 21, 2011

AppleScript identifying InDesign hidden characters #2

Back in this post, AppleScript Identifying InDesign Hidden Characters, I outlined an issue with AppleScript picking up meta-characters from InDesign that were causing false results in string evaluations. Posting my problem to the Adobe forum resulted in a couple of less than helpful suggestions that revolved around calling in the robust JavaScript. Thanks for trying, guys, but JavaScript is not the sharpest chisel in my tool box. Also, I still feel this is a bug in the CS5 programming, but I'm not going to waste my time trying to push the issue with Adobe.

I did manage to generate a fix of my own though. I was trying to avoid re-writing the original script and how it was evaluating the content, but I was not left with many options, and I set about adding in a new handler.


Instead of comparing the contents of all of the text frames on a page that share a similar script label against a pre-set list of strings, this handler counts the number of text items in each string in the list. Because the application is recording data from the meta-character, it should have at least one and if any one string in that list contains more, it is considered not empty and returns a corresponding boolean value that is evaluated by the main body of the script. True, execute the contents of the block; false, do nothing. This worked pretty well until I started testing on other templates that are used. Some of the data merge remnants would return three or more text items in what was supposed to be an empty frame! I changed the text item delimiters that AppleScript uses to count those items, but I had to insert a couple of assumptions, the first being that one set of labeled frames would always receive a price containing a decimal, if anything, and the other would always receive a string of text two or more words in length, separated by a space. I dislike doing this because it opens the door for any number of exceptions, but the data sources supported the plan. By re-setting these parameters, the text item count for an empty frame would always return "1", regardless of the number of metacharacters, as they would have no decimals or spaces to separate them.

I also cleaned out the small army of redundant tell statements directed at the application, an assigned variable that was never used in the script, a number of blocks that no longer had a function because of the logic of the new handler, and inserted some detailed documentation regarding the revisions.

A successful update, and a working solution to a satisfying challenge. Now I'm off to script a process on a baleful application, Microsoft Excel.

No comments:

Post a Comment