Applescript / Javascript > Quark XPress scripting

Case sensitive find / change

(1/2) > >>

mark1:
Hi

I have a sequence of fairly simply find / changes I want to execute.

try
set contents of every text where it is "XyZ" to "XYZ"
end try

They need, however, to be case sensitive (i.e. find and change 'XyZ" not "xyz").
The text is taken from a database so has no styling.

I'm presuming that I should use a 'considering case' statement but I just can't get it to work.

Any ideas?

Thanks

Mark

Emma:
Script didn't run quite as you'd typed it, but I suspect that was doing it from memory?

Anyway, very odd - I put it in a 'considering case' and it made no difference. So I went mad and ran this:

tell document 1 of application "QuarkXPress"
     try
          set every text of every story where it is ((ASCII character 88) & (ASCII character 121) & (ASCII character 90)) to ((ASCII character 88) & (ASCII character 89) & (ASCII character 90))
     end try
end tell

- And it STILL changed xyz to XYZ although I'd specifically given it ASCII values (and did the same when I added considering case for luck). That is very weird. Can anyone enlighten us?

Publi-Script:
Reading this, here's what "I" think:

Considring case works when Applescript is doing the work, in this case the "search" is made by Quark which uses an unknown "behind the scene" procedure that must not be case sensitive.

Emma:
Thanks Michel! Inspired. So try this....

set my_strings to {}

tell document 1 of application "QuarkXPress"
     set my_refs to object reference of every text of every story where it is "XyZ"
     
     repeat with i in my_refs
          set my_strings to my_strings & (text of i)
     end repeat
     
end tell

considering case
     repeat with j from 1 to length of my_strings
          if item j of my_strings is "XyZ" then set item j of my_strings to "XYZ"
     end repeat
end considering

tell document 1 of application "QuarkXPress"
     repeat with k from 1 to length of my_refs
          set text of item k of my_refs to item k of my_strings
     end repeat
end tell

- the work gets done outside Quark!

mark1:
That's great. I was fumbling around trying to use object references and work outside Quark, but was nowhere near this. Thank you.

As I have a few of these find / changes to execute the I have structured the script like so:


--- Code: ---
SAndR("XYZ", "123")
SAndR("xyz", "456")
---etc

on SAndR(searchstring, replacestring)
set my_strings to {}

tell document 1 of application "QuarkXPress"
set my_refs to object reference of every text of every story where it is searchstring

repeat with i in my_refs
set my_strings to my_strings & (text of i)
end repeat

end tell

considering case
repeat with j from 1 to length of my_strings
if item j of my_strings is searchstring then set item j of my_strings to replacestring
end repeat
end considering

tell document 1 of application "QuarkXPress"
repeat with k from 1 to length of my_refs
set text of item k of my_refs to item k of my_strings
end repeat
end tell

end SAndR

--- End code ---

The idea for this comes from another post on this site.

For the record this also works (I found it elsewhere), but only for entire words.
Here the 'considering case' does seem to operate within Quark.


--- Code: ---
tell application "QuarkXPress"
activate
set findText to "XYZ"
set replaceText to "xyz"
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

--- End code ---

Cheers

Mark

Navigation

[0] Message Index

[#] Next page

Go to full version