Problem Dealing With Records

Though I’ve been scripting for years, I’ve always avoided getting too deep into records. They always seemed scarier than lists and strings. Now I’m stuck.

I’m trying to write a script that will save me a little time when scripting InDesign. I often run a small script to get the properties of a page item in InDesign in order to peek at some of the item’s properties and find out how to manipulate that object. Unfortunately, using Script Editor, the returned properties are really hard to read”just an ugly block of the properties all run in together.

What I generally do now is copy the properties text out of the Script Editor results window, paste it in a text editor and use a quick find/replace action to separate the different properties with returns so I can easily read through the list.

I thought I’d automate this. But I can’t figure how to get the properties text out of Script Editor. I can’t coerce it into a string. And I can’t even loop through it and make a list out of the records because, as I understand it, I need to reference the label of each property in order to get at the property stored in a record. In this case, I don’t know the name of every record in the properties.

What I’d like to do is get this (from my results window):

{numbering format:“1, 2, 3, 4…”, positional form:none, OTF contextual alternate:true, OTF discretionary ligature:false, OTF fraction:false, OTF historical:false, OTF locale:true .

And parse it into something like this:

numbering format:“1, 2, 3, 4…”
positional form:none
OTF contextual alternate:true
OTF discretionary ligature:false
OTF fraction:false
OTF historical:false
OTF locale:true
.

Am I missing something obvious. I knew I hated records.

You might start with a chunk of code that uses an error handler to capture the string representation of a record. The result would be basically the same as what you would see in the Result window (without the formatting), so you might even be able to apply your existing substitutions to whip it into your desired format.

Alternatively, you could investigate the List & Record Tools OSAX. You could use its property access commands to extract the pieces of the record, but you would end up with the internal (four character) identifiers for system-, application-, or OSAX-defined labels (e.g. for the system-defined name, you would get “pnam”). You might be able to use a hack like run script “«class “&propertyID&”» as text” to decode the internal identifiers, but it may or may not work 100% reliably.