MACSCRPT Archives

February 2008

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Stan Cleveland <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Tue, 19 Feb 2008 13:30:39 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (84 lines)
On 2/19/08 12:56 PM, Mark J. Reed wrote:

> On Feb 19, 2008 3:13 PM, Levon Spradlin <[log in to unmask]> wrote:

>> set charInput to «data utxt00BA»

>> set charOutput to «data utxt00B0»


> 
> If you're on Leopard, note that you can use


> 
> set charInput to character id 186

> set charOutput to character id 176


> 
>>             repeat with p from 1 to count of pages

>>                 repeat with a from 1 to count of text boxes

>>                     repeat with c from 1 to count of characters

>>                         if c is charInput then


> 
> c will never be charInput; c will be equal to the numbers 1, 2, 3, 4,

> 5 . . . up to the size of each text box.  You want to test if

> "character c of text box a of page p" is equal to charinput.  First

> you need to qualify your inner loops, though.  "repeat with a from 1

> to count of text boxes of page p", "repeat with c from 1 to count of

> characters of text box a of page p", or something.
> 


> But the usual way to do this would be to set text item delimiters to

> charInput, turn the text into a list of text items, set the text item

> delimiters to charOutput, and then coerce the list of text items back

> to text.




Using TIDs is a good idea, but won't work in Quark, because it's not a
"plain text" environment. Words or characters may use different fonts,
sizes, and styles, which must be preserved. If I recall correctly, when
replacing all the text in a Quark text box (as one would when using TIDs),
it ends up applying the font, size, and style of the first character to all
the rest.

Using "find and replace" will preserve all font information and would be
much more efficient than looping through every page, text box, and character
in the document. The following code will change all occurrences through an
entire document, but you can change the 'every text of stories' bit to
something like 'every text of story 1 of text box 1 of page 1' to restrict
the scope.

set findText to "old"
set replaceText to "new"
tell application "QuarkXPress"
  tell document 1
    try
      set every text of stories whose it = findText to replaceText
    on error number -10006 -- search string not found
      -- handle the error, as desired
    end try
  end tell
end tell

HTH,
Stan C.

ATOM RSS1 RSS2