RE: Case sensitive find/replace
RE: Case sensitive find/replace
- Subject: RE: Case sensitive find/replace
- From: "Robert Short" <email@hidden>
- Date: Thu, 20 Jul 2006 16:44:51 -0700
- Thread-topic: Case sensitive find/replace
Hi Stan,
I am just catching up my messages and did not see a reply. Maybe this script will help you achieve what you need.
tell application "QuarkXPress"
activate
set findText to "Formaat"
set replaceText to "Format"
tell current box of front document
set i to count words
repeat with x from 1 to i
considering case
if word x is findText then set word x to replaceText
end considering
end repeat
end tell
end tell
Robert Short
Fanfare Media Works
Valencia, California
-----Original Message-----
From: applescript-users-bounces+rshort=email@hidden on behalf of Stan Cleveland
Sent: Tue 7/18/2006 5:03 PM
To: email@hidden
Subject: Re: 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
_______________________________________________
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