Pages-inserted/generated page numbers throw off char indexing in body text
Pages-inserted/generated page numbers throw off char indexing in body text
- Subject: Pages-inserted/generated page numbers throw off char indexing in body text
- From: Eric Hon-Anderson <email@hidden>
- Date: Thu, 28 Feb 2013 15:51:19 -0500
We use the script "tell application "Pages" to get the body text of front document" to get the text contained in a Pages document. We use other scripts to select or replace characters and words within that body text.
When we use the Insert menu's Page Number or Page Count commands to put a calculated page number into the text, the body text does not contain it. The same is true for the generated page numbers in Tables of Contents. If we use "tell application "Pages" to get character <whatever> of the body text of front document", the index of the character returned will be off-by-one (or off-by-however-many-digits-are-in-the-page-number) for all characters after the missing calculated page number.
It is less important to us to actually find out what the page numbers are than it is to be able to adjust our calculations to find the correct character index for characters after the generated page numbers.
How can we find a way to account for the character counts and locations of these generated page numbers?
STEPS TO REPRODUCE
Create a short Pages document lines. Use the Insert menu's Page Number item to insert a page number somewhere in the middle of the document. I used "Characters in this range will be at the expected offset. X Characters after that page number will be off by one." (where "X" indicates the location where I put the inserted page number).
The script "tell application "Pages" get body text of document 1" will return "Characters in this range will be at the expected offset. Characters after that page number will be off by one." Remember this string, we will count the characters in this string to see the issue.
The script "tell application "Pages to select character 55 of document 1" will select the "t" at the end of "offset" which is what we expect because the 55th character of that string is "t".
The same script for 56 will select the "." as expected, still matching that remembered string.
57 will select the space following the "." also as expected.
58 will select the "C" in "Characters", NOT the generated page number. So will 59. Only when you get to 60 do you select the "h", but at this point the count is now off--"C" was the 58th character of the remembered string, not both the 58th and 59th, and "h" was the 59th character of the string. All characters after the "h" will also be off by one.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden