RE: QuarkXpress find and replace with variables (new question)
RE: QuarkXpress find and replace with variables (new question)
- Subject: RE: QuarkXpress find and replace with variables (new question)
- From: Hans Haesler <email@hidden>
- Date: Fri, 26 Jan 2001 23:18:45 +0100
Aaron,
here are three solutions which consider case.
BUT... with #1 and #2 any local formatting will be lost.
If this would be a problem, then, please, consider solution #3...
---
property list1 : {"one", "One"}
property list2 : {"uno", "Uno"}
on open y
tell application "QuarkXPress 4.11"
activate
open y
tell document 1
set newStory to story 1 of text box 1
repeat with i from 1 to count of list1
set list1item to item i of list1
set list2item to item i of list2
set newStory to my searchReplace(list1item, list2item, newStory)
end repeat
set story 1 of text box 1 to newStory
end tell
end tell
end open
on searchReplace(sStr, rStr, tStr)
set AppleScript's text item delimiters to sStr
set aList to (every text item of tStr)
set AppleScript's text item delimiters to rStr
set tStr to aList as string
set AppleScript's text item delimiters to {""}
return tStr
end searchReplace
---
The second solution is shorter but needs the OSAX "RegEx Commands":
---
property list1 : {"one", "One"}
property list2 : {"uno", "Uno"}
on open y
tell application "QuarkXPress 4.11"
activate
open y
tell document 1
set storyOne to story 1 of text box 1
repeat with i from 1 to count of list1
set list1item to item i of list1
set list2item to item i of list2
set storyOne to (REReplace storyOne pattern list1item with list2item)
end repeat
set story 1 of text box 1 to storyOne
end tell
end tell
end open
---
The third solution preserves local formatting by saving the text as
XPress Tags to a file. Then it reads it in a variable, performs the S&R
(using RegEx), writes the text to a file before loading it in the text box.
---
property tagsPath : (path to scripting additions folder as string) & "tagsFile"
property list1 : {"one", "One"}
property list2 : {"uno", "Uno"}
on open y
tell application "QuarkXPress 4.11"
activate
set convert quotes to true
set import styles to true
open y
tell document 1
save story 1 of text box 1 in tagsPath as "TEXT"
set storyOne to read file (tagsPath)
repeat with i from 1 to count of list1
set list1item to item i of list1
set list2item to item i of list2
set storyOne to (REReplace storyOne pattern list1item with list2item)
end repeat
try
open for access file tagsPath with write permission
set eof of file tagsPath to 0
write storyOne to file tagsPath
close access file tagsPath
on error
close access file tagsPath
end try
try
set story 1 of text box 1 to alias tagsPath
on error
end try
end tell
end tell
end open
---
The RegEx command line can be replaced by the call of the S&R handler
of the first solution.
One problem, however, is not solved: how do you make sure that you don't
get unwanted changes, e.g. "alone" modified to "aluno"?
Hans
---
Hans Haesler | email@hidden