here's the AppleScript shown in Session 3 of the QuarkXPress Masterclass. It does a multiple find/change on (one or) multiple documents.
All you need is a folder of QuarkXPress files that have the ending ".qxp" (all these will be processed) and a tab-delimited (not comma separated) text file that lists the find/change pairs. You can use a text editor, Excel (export as tab-separated text) or even QuarkXPress (import/export text, encoding Mac Roman) to create such a tab separated list.
Please open Apple's AppleScript-Editor and paste all of the code in there:
- Code: Select all
-- Script to apply several Find/Change pairs in one go at all documents in a given folder
-- Experimental script, USE AT YOUR OWN RISK!
-- Make sure that you have a backup beforehand
-- Based on a script idea by user ScriptingAce in forum http://forums.quark.com
-- Modified by Matthias Guenther
-- Reminder dialog that all documents should be closed, could probably be improved to save and close all documents automatically
display dialog "Please first close all documents in QuarkXPress to run this script!" & return & "And make sure that you have a recent backup of your files!" buttons {"All documents are closed and I have a backup!", "Cancel"} default button 2 with icon stop
-- Locate the folder with all QuarkXPress documents
-- Script will work on all files having a file extension of .qxp
set QFolder to "Please locate the folder containing your QuarkXPress files:" & return & "(All files with the file extension of .qxp will be processed)" & return & return & "WARNING: Changes will be applied and saved without prompting. Have a backup of your files before proceeding!"
set Doc_Folder to (choose folder with prompt QFolder) as text
set theFiles to {}
tell application "Finder"
tell folder Doc_Folder
repeat with i from 1 to count of files
if name extension of file i is "qxp" then
set end of theFiles to file i as text
end if
end repeat
end tell
end tell
-- Load the find/change pairs out of a Tab Separated file
-- Make sure all pairs are defined as followed: SEARCHSTRING TAB REPLACESTRING RETURN
set QFile to "Please locate your text file that contains the Tab Delimited Find/Change Pairs:"
set Search_File to (choose file with prompt QFile) as text
set Search_Rows to read file Search_File using delimiter {return}
set Search_Items to {}
repeat with This_Row in Search_Rows
set end of Search_Items to my GetTextItem(This_Row as text, tab, 0)
end repeat
-- Have QuarkXPress open all files and apply the find/change pairs
-- WARNING: As QuarkXPress afterwards saves the changes without warning, make sure you have a backup of your original file
tell application "QuarkXPress"
activate
repeat with oneFile in theFiles
open file oneFile
tell document 1
repeat with ThisPair in Search_Items
set {searchstring, replaceString} to ThisPair as list
tell every story
try
set (every text where it is searchstring) to replaceString
end try
end tell
end repeat
end tell
close document 1 saving yes
end repeat
end tell
-- Sub Routines
on GetTextItem(ThisString, ThisDelim, ThisItem)
-- ThisString -> String to look in
-- ThisDelim -> Text element that delimit the string
-- ThisItem -> Number of the element to return (0 for all)
copy the text item delimiters to OldDelims
set the text item delimiters to ThisDelim
if class of ThisItem is list then
set fromItem to (item 1 of ThisItem) as integer
set toitem to (item 2 of ThisItem) as integer
set arrItem to (text items fromItem thru toitem of ThisString)
else
set arrItem to every text item of ThisString
end if
set the text item delimiters to OldDelims
if class of ThisItem is list then
return arrItem as text
else
if ThisItem is not equal to 0 then
return (item ThisItem of arrItem) as text
else
return arrItem -- return every items
end if
end if
end GetTextItem
I copied large parts of the great script that ScriptingAce posted here (viewtopic.php?f=21&t=18872&p=88291&hilit=pairs#p88293), I just slightly modified it.
As explained, AppleScripts typically overwrite files, so make sure you have a backup of your files before running it against it. Also, though I tested it personally (but just with QuarkXPress 10), it was under no means extensively tested.
Enjoy! And you might also want to make that a runtime only.
And maybe the AppleScript community, Emma, Ace, JMS, and all the others here, will enhance it further.
Thanks
Matthias