I am trying to creat a script for quark do do a find/change. I can do it in InDesign, looking like this:-
set myreturn to search myselection for return
repeat with n from (count of myreturn) to 1 by -1
set contents of item n of myreturn to return & return
end repeat
Can anyone tell me of an equivalent way to acheive this in Quark?
set searchitem to return
set replaceitem to return & return
tell application "QuarkXPress™ "
activate
tell document 1
set myselection to object reference of selection
set stringTOsearch to myselection as string
set newString to my searchANDreplace(stringTOsearch, searchitem, replaceitem)
set text of myselection to newString
end tell
end tell
on searchANDreplace(stringTOsearch, searchitem, replaceitem)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to searchitem
set thetextitems to text items of stringTOsearch
set AppleScript's text item delimiters to replaceitem
set stringTOsearch to thetextitems as string
set AppleScript's text item delimiters to oldDelim
return stringTOsearch
end searchANDreplace
How would I make this search my whole document instead of just the box I have selected.
search document
tell document 1
set myselection to object reference of selection
set stringTOsearch to myselection as string
set newString to my searchANDreplace(stringTOsearch, searchitem, replaceitem)
set text of myselection to newString
end tell
This solution seems very long winded compared to the InDesign alternative. Also, I am going to want to refer back to all instances of the search item to carry out further formatting issues (repeat from 1 to count of serches and do further seaches within that paragraph) Does this make any sense???
here is some indesign code that I am refering to:-
set myselection to selection
set mypound to search in myselection for “£”
repeat with n from (count of mypound) to 1 by -1
set mypara to object reference of paragraph 1 of item n of mypound
set myline1 to line 1 of mypara
if contents of line 1 of mypara does not contain return then
set contents of insertion point -1 of line -2 of mypara to return
try
set contents of insertion point -1 of line -3 of mypara to return
end try
try
set contents of insertion point -1 of line -4 of mypara to return
end try
end if
end repeat
If quark cannot do this sort of search, then I am going to have to stick with ID.
I am a beginner with Applescript, and still learning. It seems that the quark solution is a little too long wined to get my little head around!
Could you be a bit more specific on what you are tying to do with the script? Are you searching for a specific character, word, or paragraph and what formatting do you need to do with the new text?
I agree the ID solution seems to be somewhat more concise. But I have one other question, what if you were doing the find from Filemaker, and needed to do a replace using a related value from Filemaker?
I most commonly have is to delete a string " §" (tab+sibling) with “” (nothing) but am having issues getting item 1 of “”. For this script, I need to be able to get either a single character or a string and replace it with another string or character. To delete a string or character, I am replacing with “”.
display dialog "Please enter the text you would like to search for:" default answer " §"
set originalStringList to text returned of result
display dialog "Please enter your replacement text:" default answer ""
set replaceStringList to text returned of result
set originalStringCount to count originalStringList
repeat with s from 1 to originalStringCount
xPstringReplace({}, {}, item s of originalStringList, item s of replaceStringList) --Can't get item 1 of ""
end repeat
on xPstringReplace(pageList, textboxList, originalString, replaceString)
set sourceFolder to choose folder with prompt "Choose the folder to process."
tell application "Finder" to set theFiles to files of folder sourceFolder whose kind contains "QuarkXPress"
repeat with oneFile in theFiles
tell application "QuarkXPress"
open oneFile
tell document 1
if pageList = {} then
set pageList to index of every page
if class of pageList ≠list then set pageList to {pageList}
end if
set pageCount to count of pageList
repeat with p from 1 to pageCount
tell page (item p of pageList)
if textboxList = {} then
set textboxList to index of every text box
if class of textboxList ≠list then set textboxList to {textboxList}
end if
set textboxCount to count of textboxList
repeat with t from 1 to textboxCount
tell story 1 of text box (item t of textboxList)
repeat
try
set stringOffset to my getStringOffset(contents, originalString)
set characters stringOffset thru (stringOffset + (length of originalString) - 1) to ""
set character stringOffset to (replaceString & character stringOffset)
on error errmsg
exit repeat
end try
end repeat
end tell
end repeat
end tell
end repeat
--close saving yes
end tell
end tell
end repeat
end xPstringReplace
on getStringOffset(xPstory, originalString)
return offset of originalString in xPstory
end getStringOffset
Model: Dual 2.3GHz G5
AppleScript: 2.1.1/Script Debugger4
Browser: Firefox 3.0
Operating System: Mac OS X (10.4)
tell application "QuarkXPress Passport"
tell document 1
set text of every text of every story where it is "SEARCHSTRING" to "REPLACESTRING"
end tell
end tell
For better performance you can use do script:
script theScript
tell application "QuarkXPress Passport"
tell document 1
set text of every text of every story where it is "SERCHSTRING" to "REPLACESTRING"
end tell
end tell
end script
tell application "QuarkXPress Passport"
do script {theScript}
end tell
I too seem to be having issues with this quarkXpress script…
I am pulling a source file from excel and searching the list line by line to replace specific content in a 32 page document…
I had been able to cobble together scripts to perform simple search replace in a single story but this one I just can’t seem to wrap my head around… Can anyone offer guidance or a solution ?
display dialog "Please enter the text you would like to search for:" default answer "4C"
set originalStringList to text returned of result
display dialog "Please enter your replacement text:" default answer "33aa"
set replaceStringList to text returned of result
set originalStringCount to count originalStringList
repeat with s from 1 to originalStringCount
xPstringReplace({}, {}, item s of originalStringList, item s of replaceStringList) --Can't get item 1 of ""
end repeat
on xPstringReplace(pageList, textboxList, originalString, replaceString)
set sourceFolder to choose folder with prompt "Choose the folder to process."
tell application "Finder" to set theFiles to files of folder sourceFolder whose kind contains "QuarkXPress"
repeat with oneFile in theFiles
tell application "QuarkXPress"
open oneFile
tell document 1
if pageList = {} then
set pageList to index of every page
if class of pageList ≠list then set pageList to {pageList}
end if
set pageCount to count of pageList
repeat with p from 1 to pageCount
tell page (item p of pageList)
if textboxList = {} then
set textboxList to index of every text box
if class of textboxList ≠list then set textboxList to {textboxList}
end if
set textboxCount to count of textboxList
repeat with t from 1 to textboxCount
tell story 1 of text box (item t of textboxList)
repeat
try
set theString to my getString(contents, originalString)
set getString to searchReplace(theString, originalString, replaceString)
on error errmsg
exit repeat
end try
end repeat
end tell
end repeat
end tell
end repeat
--close saving yes
end tell
end tell
end repeat
end xPstringReplace
on getString(xPstory, originalString)
return text of originalString in xPstory
end getString
on searchReplace(theString, originalString, replaceString)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to originalString
try
set theList to text items of theString
set AppleScript's text item delimiters to replaceString
set theString to theList as string
set AppleScript's text item delimiters to oldDelim
on error
set AppleScript's text item delimiters to oldDelim
end try
return theString
end searchReplace
I gan gather the string to prepare each textbox separately but can’t seem to get the replace function to work…
Any help much appreciated.
Model: G4 1.25 GHz 1 GB RAM
AppleScript: 2.2.1
Browser: Safari 528.16
Operating System: Mac OS X (10.4)