This script is running just fine on Snow Leopard, and using InDesign CS4, but it is hanging up on the tab stop (character id 9) on a system using Tiger and InDesign CS4. Is there any other way to call out the tab character, or is there some known bug with that mixture? Should I be adding in some kind of unicode stuff or something?
The error message on the Tiger system says it cannot make character id 9 into a string.
This script is made to go through an index list with cross references that are placed before the page number (that’s just the way it is generated!), and this moves those after the page number.
tell application "Adobe InDesign CS4"
set enable redraw of script preferences to false
set find text preferences to nothing
set case sensitive of find change text options to false
set include footnotes of find change text options to false
set include hidden layers of find change text options to false
set include locked layers for find of find change text options to true
set include locked stories for find of find change text options to true
set include master pages of find change text options to false
set whole word of find change text options to false
set myTextObjects to {text style range, paragraph, text column, text, story}
if (count documents) > 0 then
set mySelection to selection
if (count mySelection) > 0 then
if class of item 1 of mySelection is in myTextObjects then
tell document 1
try
set myCharacterStyle to character style "Italic_Index"
on error
--The character style did not exist, so create it.
set myCharacterStyle to make character style with properties {name:"Italic_Index"}
end try
set myText to item 1 of mySelection
repeat with i from (count paragraphs of myText) to 1 by -1
set workPara to paragraph i of myText
--identify the paragraphs that have a "See also..." cross reference line
if workPara contains "see" then --only have to go through the repeat process if the cross reference is there
--get the character number of the start of "see"
set offsetOne to (text offset of "see" in workPara)
--get the character number of the string just before the tab stop
set offsetTwo to ((text offset of (character id 9) in workPara) - 1) --character id 9 is the tab character
--next, get the string from offsetOne thru offsetTwo
set moveText to (characters offsetOne thru offsetTwo of workPara) as string --if we don't coerce to string, it will be a list
--we need the text from beginning of paragraph to start of cross reference
set firstText to (characters 1 thru (offsetOne - 1) in workPara) as string
--now the text from end of cross reference to end of paragraph (the tab and page#)
--by subtracting one character from end of para, we avoid grabbing the para return
set lastText to (characters (offsetTwo + 1) thru ((count of characters of workPara) - 1) in workPara) as string
--re-order all elements to make new paragraph content
set newPara to firstText & lastText & (character id 9) & moveText & return
tell application "Adobe InDesign CS4"
set find what of find text preferences to workPara
tell parent story of myText
set {workPara_textObjchar} to (find text workPara)'s item 1's {object reference}
--return {ParaB_HO, ParaB_base, ParaB_textPar, ParaB_textObjchar}
set contents of (workPara_textObjchar) to newPara
end tell
end tell
end if
end repeat
--this new repeat finds all cross-references to apply the right character style
repeat with i from (count paragraphs of myText) to 1 by -1
set stylePara to paragraph i of myText
if stylePara contains "see" then
tell application "Adobe InDesign CS4"
set find what of find text preferences to stylePara
tell parent story of myText
set {stylePara_textObjchar} to (find text stylePara)'s item 1's {object reference}
tell stylePara_textObjchar
set applied character style of characters (text offset of "see" in stylePara) thru (count of characters of stylePara) to myCharacterStyle
end tell
end tell
end tell
end if
end repeat
end tell
else
display dialog "Text is not selected, or too little text is selected. Please select several paragraphs and try again."
end if
else
display dialog "Nothing is selected. Please select some text and try again."
end if
else
display dialog "No documents are open. Please open a document and try again."
end if
end tell
Thanks for the help!