Find the word and replace one letter on found word in the wo

Discuss AppleScripting for QuarkXPress 10, 9 & 8 (and before)
Post Reply
mubeen.s
Posts: 0
Joined: 13 May 2013, 06:15

Find the word and replace one letter on found word in the wo

Post by mubeen.s » 13 May 2013, 01:48

Hi,
I want to find a word from the worrd document and replace it one of
letter of found word. I am struggling to do this.
Please any one one help on this.

I have placed the code here


set textStart to "wor"
textEnd to "d1.1 "

on findReplace(textStart, textEnd)
display dialog textStart & "**" & textEnd & "**"
tell application "QuarkXPress"
activate
tell document 1
set selectedTextBox to 0
repeat with p from (count of pages) to 1 by -1
show page p
tell page p
repeat with tb from 1 to count of text boxes
tell text box tb
if (selected is true) then
set selectedTextBox to tb
--set selectedTextBox to text box tb
set txt to text of text box selectedTextBox
display dialog tb & " -" & txt
--set theText to text of current box
display dialog text of selectedTextBox
set theText to text of selectedTextBox
display dialog textStart
set selStart to count characters of (my getTID(theText, textStart, 1))
set selEnd to count characters of (my getTID(theText, textEnd, -1))
display dialog selStart & "***" & selEnd & "**"

--set selection to text from character selStart to character (-selEnd) of current box
set selection to text from character selStart to character (-selEnd) of selectedTextBox
display dialog selection as string
set sel to the selection
tell sel
set (every text where it is textEnd) to ""

end tell
end if
end tell
end repeat
end tell
end repeat
end tell
end tell
end findReplace

on getTID(theString, theDelimiter, theItem)
set theReturn to ""
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to theDelimiter
try
set theList to text items of theString

if theItem = 0 then
set theReturn to theList
else
set theReturn to item theItem of theList
end if
set AppleScript's text item delimiters to oldDelim
on error
set AppleScript's text item delimiters to oldDelim
end try
return theReturn
end getTID

Emma
Posts: 657
Joined: 07 Jul 2004, 08:43

Find the word and replace one letter on found word in the wo

Post by Emma » 13 May 2013, 01:55

It looks as if you've got hold of a script without really understanding it.
Can you describe what you are trying to do in more detail?

mubeen.s
Posts: 0
Joined: 13 May 2013, 06:15

Find the word and replace one letter on found word in the wo

Post by mubeen.s » 13 May 2013, 15:50

Hi,
I want to find a word in the Quark file and replace a letter of found word. I want to remove "1." from the found word (ex., table 1.)
For Ex., table 1.1 => table 1
For that I tried the below code for selecting the word "table 1.". Using below code, I can do this process for current textbox but I want to do for a whole document. In the previous post, I have posted the code for whole document process which I tried.It is not woking..
Please help me to complete this process.

set textStart to "table"
set textEnd to "1."
set selStart to count characters of (my getTID(theText, textStart, 1))

set selEnd to count characters of (my getTID(theText, textEnd, -1))
set selection to text from character selStart to character (-selEnd) of selectedTextBox
disply dialog selection as string
set sel to the selection
tell sel
set (every text where it is textEnd) to ""
end tell

Post Reply

Return to “QuarkXPress 8, 9 & 10: AppleScript”