Re: search and replace question
Re: search and replace question
- Subject: Re: search and replace question
- From: Steven Angier <email@hidden>
- Date: Fri, 18 Jan 2002 09:50:47 +1100
- Organization: Macscript.com
Elmer Banate wrote:
>
Hi All,
>
>
I'm trying to replace the word "Common" in every
>
master pages, but when I run my script I'm
>
encountering this error message "QuarkXPress 4.11 got
>
an error: every story of master spread of document 1
>
doesn't understand the searchReplace message."
The error occurred because the line was within a "tell application QuarkXPress" block,
AppleScript passed the instruction to "searchReplace()" to QuarkXPress instead of using the
function called "searchReplace()" defined in your script. The way around this problem is to
precede your function call with "my"; this tell's AppleScript to look for the object
(function) within the script.
BUT, That error is really only the tip of the iceberg...
The next problem is that your search and replace text won't actually replace any text in
your document because:
a) your search and replace technique is only changing a value in memory, not in your
document
b) the script will errror again because you aren't passing enough parameters to your
function anyway
c) because replace_text is a string and not a list of string, when you repeat through
each item of replace_string, you will actually get one character at a time (which I doubt
is what you want)
For example:
item 1 of "Some text"
--> "S"
You will need to either lose the repeat loop or (better) coerce the replace_string to a
list of one item, thus:
if class of replace_string is not list then set replace_string to {replace_string}
The next problem is that you are trying to target "master spread". Master Spread is a
property of a page or spread. For example, if you were to target page 1 of your document
and get the name of its master spread you could try:
tell app "QuarkXPress 4.11"
tell document 1
return name of master spread of page 1
end
end
--> "A-Master A" (or what every the name of the applied spread is)
I suspect that this is not what you want, and this will fail anyway because you don't
specify a page or spread.
If you want to perform a find and replace on all master pages you should use (making sure
that search_string and replace_string are strings (not lists of strings):
tell app "QuarkXPress 4.11"
tell master document 1
set every text of stories where it is search_string to replace_string
end
end
by adding a reference to a specific spread, we can limit the script's action
tell app "QuarkXPress 4.11"
tell master document 1
tell spread 1 -- (or by name if you prefer, e.g. "A-Master A")
set every text of stories where it is search_string to replace_string
end
end
end
Keep at it. You will get there in the end!
Steven Angier
Macscript.com