Author Topic: i need help to script find and replace  (Read 3245 times)

0 Members and 1 Guest are viewing this topic.

Offline Vitor Silva

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
  • Gender: Male
i need help to script find and replace
« on: September 30, 2010, 05:53:23 AM »
Hi,

i have a script

----
tell document 1 of application "QuarkXPress"
   activate
   
   set every text of every story whose it is "hão-de" to "hão de"
   
end tell
----

works well, but change all words same words that begin with capitals.

I need the search to be case sensitive and replacing the exact word (eg "they will" to "will" and "des-will" stay as it is not the same word)

Does it help me?

regards,

Vitor Silva
Vítor Silva

_______________________
MacBookPro | OS X 10.6.4
Quark 6.5 | 8.1.6
Adobe Design Premium  CS4 | CS5

Offline Emma

  • Full Member
  • ***
  • Posts: 205
  • Karma: 9
Re: i need help to script find and replace
« Reply #1 on: September 30, 2010, 05:55:21 AM »
Can't test this, but I seem to remember you can put:

considering case
set every.....
end considering
------------
Quark 6.5
OS X 10.4.8
G4

Offline Vitor Silva

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
  • Gender: Male
Re: i need help to script find and replace
« Reply #2 on: September 30, 2010, 09:35:55 AM »
unfortunately does not work   :-[
Vítor Silva

_______________________
MacBookPro | OS X 10.6.4
Quark 6.5 | 8.1.6
Adobe Design Premium  CS4 | CS5

Offline cdms

  • Full Member
  • ***
  • Posts: 111
  • Karma: 6
  • Gender: Male
Re: i need help to script find and replace
« Reply #3 on: October 01, 2010, 04:19:26 AM »
I would have gone with Emma's suggestion here but, your right, Quark is ignoring the considering case statement. There does not appear to be any obvious way of scripting the find/change functionality >:( so the only way I can think will be to do the replace outside Quark.

This works but only if the find and replace strings are the same length.

Code: [Select]
set findString to "Test"
set replacestring to "test"

tell application "QuarkXPress"
tell document 1
set theTexts to every text of every story whose it is findString
end tell
end tell

considering case
repeat with i from 1 to count of theTexts
if item i of theTexts = findString then
set item i of theTexts to replacestring
end if
end repeat
end considering

tell application "QuarkXPress"
tell document 1
set thePossibles to object reference of every text of every story whose it is findString
repeat with i from 1 to count of thePossibles
set contents of item i of thePossibles to item i of theTexts
end repeat
end tell
end tell



Offline Vitor Silva

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
  • Gender: Male
Re: i need help to script find and replace
« Reply #4 on: October 01, 2010, 10:18:49 AM »

Thanks,

but still having the problem  :-[ since I have words that are left with fewer letters ex. from "actividades" to "atividade".
And change all the words that have the string ex: change the worlds "actividade" and "actividades" should only change when the first one.

Vítor Silva

_______________________
MacBookPro | OS X 10.6.4
Quark 6.5 | 8.1.6
Adobe Design Premium  CS4 | CS5

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: i need help to script find and replace
« Reply #5 on: October 01, 2010, 10:58:13 AM »
Hi Victor,

This is because the offsets of the "references" change when you replace a word by a longer or shorter one. To prevent that, simply work backwards (from the end of the document to the front), that references that have not yet been changed remain unaffected.

Quote
001     set findString to "Test"
002     set replacestring to "test"

003     --(*
004     tell application "QuarkXPress"
005          tell document 1
006               set theTexts to every text of every story whose it is findString
007          end tell
008     end tell

009     considering case
010          repeat with i from 1 to count of theTexts
011               if item i of theTexts = findString then
012                    set item i of theTexts to replacestring
013               end if
014          end repeat
015     end considering

016     tell application "QuarkXPress"
017          tell document 1
018               set thePossibles to object reference of every text of every story whose it is findString
019               repeat with i from (count of thePossibles) to 1 by -1
020                    set contents of item i of thePossibles to item i of theTexts
021               end repeat
022          end tell
023     end tell
Notes:
• The line numbers included with this script are there to aid future discussions. In order to use this script, you will have to strip them all from the code.


HTH
Michel Lemieux
Forum Administrator
-------------------------
OS X 10.6.4
Quark 6.5 / 7.5 / 8.1.6
Adobe Design Premium CS / CS2 / CS3 / CS4 / CS5
Script Debugger 4.5

Offline Vitor Silva

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
  • Gender: Male
Re: i need help to script find and replace
« Reply #6 on: October 02, 2010, 05:52:03 AM »
Thanks Michel,

but i still have a problem, because if i have the words "test" and "tests" and only need to change the word "test" and not the word "tests" they change the two diferent words

Vítor Silva
Vítor Silva

_______________________
MacBookPro | OS X 10.6.4
Quark 6.5 | 8.1.6
Adobe Design Premium  CS4 | CS5

Offline cdms

  • Full Member
  • ***
  • Posts: 111
  • Karma: 6
  • Gender: Male
Re: i need help to script find and replace
« Reply #7 on: October 04, 2010, 02:15:04 AM »
In lines 6 and 18 from Michel's code, try changing 'every text' to 'every word'.

Offline Vitor Silva

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
  • Gender: Male
Re: i need help to script find and replace
« Reply #8 on: October 04, 2010, 04:18:52 AM »
i tried, but in words (portugues) like "hão-de" it not consider a word but two words.
Vítor Silva

_______________________
MacBookPro | OS X 10.6.4
Quark 6.5 | 8.1.6
Adobe Design Premium  CS4 | CS5

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: i need help to script find and replace
« Reply #9 on: October 11, 2010, 09:39:18 AM »
Hi! In Script Editor, search the dictionaries for Delimit and read more about it. You'll be to set - as part of a word (couldn't help you further at the moment for I'm migrating my old G5 to a new Mac Pro).

Be careful at changing Delimits! Always store current Delimits prior to changing anything in there!!!
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz • 10 Go 1066 MHz DDR3 • Mac OS 10.8.5 • QuarkXPress 9.5.4.1 • Adobe CS5 =