Howdy–
It’s just like the title says… I’m creating a series of indices and a TOC, and I’m looking to get the value of the auto page number character, but all I get is “auto page number” returned. Example code is below. If I go straight to the contents, I get the same thing. If I try as string I get the same thing. If I try as integer I get “Can’t make «constant ****SApn» into a integer.” I’ve been searching high and low in various forums to no avail, but, surely, there must be a way!
repeat with q from 1 to (get count of page items in thisPage)
set thisPageItem to page item q in thisPage
set theLabel to GetLabel(thisPageItem) of me
if theLabel is "folioFrame" then
set thisPageItemProperties to properties of thisPageItem
set theParentStory to parent story of thisPageItemProperties
set theParentStoryProperties to properties of theParentStory
set the clipboard to contents of theParentStoryProperties as string
set end of pageNumberArray to the clipboard
end if
end repeat
--result: {"auto page number", "auto page number", "auto page number", "auto page number", "auto page number", "auto page number", "auto page number", "auto page number", "auto page number"}
Essentially all of this would be called once a search has returned successful results.
tell application "Adobe InDesign CS2"
tell document 1
repeat with p from 1 to (get count of pages)
set thisPage to page p
tell page thisPage
set pageObject to object reference of thisPage
repeat with q from 1 to (get count of page items in thisPage)
set thisPageItem to page item q in thisPage
set theLabel to GetLabel(thisPageItem) of me
if theLabel is "folioFrame" then
set thisPageItemProperties to properties of thisPageItem
set theParentStory to parent story of thisPageItemProperties
set theParentStoryProperties to properties of theParentStory
set the clipboard to contents of theParentStoryProperties as integer
set end of pageNumberArray to the clipboard
end if
end repeat
end tell
end repeat
end tell
end tell
on GetLabel(thePageItem)
tell application "Adobe InDesign CS2"
tell document 1
set theProperties to properties of thePageItem
return label of theProperties
end tell
end tell
end GetLabel
Auto page number is a special character placed in a text frame that numbers pages based on the page numbering scheme chosen for the document.
As I see it, the problem I’m having is I’m seeing a number in my text frame, that InDesign still sees the content of the frame as an object and not the actual text it’s displaying. In addition, it acts like an object, but it’s not something I can interact with via Applescript.
Through the GUI, it’s invoked by going to Type>Insert Special Character>Auto Page Number or typing “^#”. It doesn’t actually show a character, it just shows the master page letter in master pages and the current page number in layouts according to the starting page number set in the document.
Table of Contents and Indices are functions of InDesign itself, so I’m a tad curious what you’re up to with the AppleScript. In other words, why have AppleScript create these things when you could maybe just easier have AppleScript fire-off the InDesign fuctions that just do it for you. Maybe I’m missing the point, not uncommon.
In any case, if you don’t actually want InDesign’s own Table of Contents feature to make it for you, could you find a way to take advantage of it’s functionality to get your page numbers somehow? Perhaps have it generate a “temporary” table of contents that you could parse, then simply delete this temporary and use your script to continue it’s own generation tasks?
Maybe the same methodology for your Indices generator?
For those that don’t know, InDesign’s TofC and Index generators are automations, not dynamic. Based on style or tag criteria they scan a document and create a static TofC or Index. If anything changes, the user must re-generate the TofC and Index manually by calling the feature again. The text/layout either feature generates is otherwise static once generated. No syncing, no dynamic changes.
Another question/idea: are the page number displayed by the auto-generation on the Master Page the same as shown under the thumbnails in the Pages pallette? If so, maybe instead of looking for a physical page element (i.e. the auto-number object), can you use AppleScript to get the “page currently selected” or similar construct?
To be honest, I don’t think the Index and TOC tools even came up in conversation for this project. For one, being in book publishing, if we ever need a TOC we just make it ourselves, and when we need an index, we hire an indexer. We’ve been burned so many times by Quark’s tools that built in TOC and Index tools, really, aren’t even an option for us anymore. Also the fact that the catalog is done entirely in XML, we were hoping to be able to take advantage of that. Certainly, InDesign isn’t Quark (thank goodness), and we’ll give its built in TOC and Index tools a try.
I still think this poses an interesting problem that what’s seen visually on the page through an untouchable object can’t be turned into editable text even though it’s contained in a story object. I’m (only a little) surprised that Adobe hasn’t thought of this already. My other motive for figuring this out is getting clean text extractions out of InDesign pages for various purposes. We use TextTractor in Quark, but aren’t aware of a similar tool for InDesign.
We don’t use the TOC or Indexing features in InDesing or Quark where I work either, typically the client supplies the text that they want for these sections of the book.
If you need to get the page number of the page that something is placed on then you need to get the name of the parent page of the page item. Since this might be barried a few levels deep in the parent child relationship you need to dig down untill you get the parent page of the item. Something like this will work to do that:
tell application "Adobe InDesign CS2"
set x to object reference of selection
tell document 1
set PageNo to ""
repeat while PageNo is ""
if class of parent of x is page then
set PageNo to name of parent of x
else if class of parent of x is story then
set x to item 1 of parent text frames of x
else
set x to object reference of parent of x
end if
end repeat
end tell
end tell
return PageNo
This should step back through the hierarchy of the item whether the selected item is text, and inline graphic, the text in an inline graphic or an image in an inline graphic. It returns the name of the page that the selection is placed on, even if it is in a story that is linked to a text frame on another page.
I hope that this helps, it’s hard to get more detailed in how you need it to work without more information.
So, pardon my confusion, the name property of the page contains the page number as determined by the page number options for the document?
Your script did give me an idea, however. I could write a script that applies the proper page number to the label property, and then get the label of the page itself. But, that’ll be Plan B if your script gives what I need.
Jerome, I just tried your code snippet and it returned exactly what I was looking for. Thanks so much for that tip because that’s going to save us hours of work.