• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Case sensitive find/replace
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Case sensitive find/replace


  • Subject: Re: Case sensitive find/replace
  • From: Stan Cleveland <email@hidden>
  • Date: Tue, 18 Jul 2006 17:03:48 -0700
  • Thread-topic: Case sensitive find/replace

On 7/18/06 7:24 AM, Jan Bultereys wrote:

> No, this doesn't work..... Case sensitive is still ignored
>
> Any other idea's are much appreciated,

The code below does what you want, but getting it done requires some
trickery. First, we must get references to all occurrences of the "find"
text, regardless of case. Then we must look at the text content at each
found location, testing it for case. When there's a match, we replace it
with our "replace" text.

There are two complications. The number of instances of the "find" text in
the box will change with each replacement, thus we need to keep track of
occurrences of the text with an adjustable index. Also, because the total
number of characters contained in the box may change with each replacement,
we must capture each new occurrence of the "find" text just before we need
it, because object references to text break when this number changes.

-- BEGIN CODE
set findText to "Formaat"
set replaceText to "Format"

tell application "QuarkXPress"
    set i to 0 -- initialize the index
    repeat
        set i to i + 1 -- increment index
        tell current box
            try
                set thisLocation to object reference of text i ¬
                    where it is findText
            on error number -1728 -- no more occurrences found
                exit repeat
            end try
        end tell
        set theText to (contents of thisLocation) as text
        considering case
            if theText is findText then -- case matches, so replace text
                set text of thisLocation to replaceText
                set i to i - 1 -- decrement index
            end if
        end considering
    end repeat
end tell
-- END CODE

I hope that my explanation is clear and not overly concise. Let me know if
you need further clarification.

Stan Cleveland
Color Technology Inc.
Porltand, Oregon

"Common sense is the collection of prejudices acquired by age eighteen."
--Albert Einstein


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • RE: Case sensitive find/replace
      • From: "Robert Short" <email@hidden>
References: 
 >Re: Case sensitive find/replace (From: Jan Bultereys <email@hidden>)

  • Prev by Date: Re: what the heck - text manipulation script
  • Next by Date: Re: getting the image file of a mounted disk image
  • Previous by thread: Re: Case sensitive find/replace
  • Next by thread: RE: Case sensitive find/replace
  • Index(es):
    • Date
    • Thread