-
I opened your script and ran it and it ran fine.
-
Next, I created a dummy Quark file and hooked it up to your script and told the script to set the text of “theOffer” of your script to text box 1 of the Quark file. Only the selected offer appeared in the Quark text box and not the entire word doc. Okay so far.
-
I hooked up the dummy Quark file to my script, and (* *) the part where I seperate out the word file into parts with TextEdit, and just took the entire result and dumped it into the Quark file. Only the offer I had selected appeared. Okay so far.
What this tells me is that I am not addressing “theOffer” when I seperate out the word file into parts, I am addressing the original word file.
So, after:
set theOffer to my extractBetween(theText, whichOne, "Offer " & nextNum)
How do I get “theOffer” in TextEdit to disect it into the parts I need? The answer is probably very simple, but so far it has eluded me, I keep coming up with the entire text.
But when I dump the results into a Quark text box, I get just the selected offer, even when I insert “set AppleScript’s text item delimiters to {”“}”
Try this, SDI;
to extractBetween(SearchText, startText, endText)
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to startText
set endItems to text of text item -1 of SearchText
set AppleScript's text item delimiters to endText
set beginningToEnd to text of text item 1 of endItems
set AppleScript's text item delimiters to tid
return beginningToEnd
end extractBetween
set whichOne to ("Offer 3")
set nextNum to 1 + (item -1 of characters of (whichOne as string))
set aFolder to choose folder with prompt "Choose Folder to Search..."
set strSearchValue to "ABCD" --the client file code beginning every file name
set lstFolderContents to list folder aFolder without invisibles
-- Repeat through the folder's content
repeat with i from 1 to (count of lstFolderContents)
set strFile to ((aFolder & item i of lstFolderContents) as string) as alias
tell application "TextEdit" to set theText to text of document 1 of application "TextEdit"
set theOffer to my extractBetween(theText, whichOne, "Offer " & nextNum)
-- the rest of the script dealing with getting the text into QuarkXPress file goes here"
end repeat
I tried it but I still wound up with offer 1.
However, when I plug in the dummy quark file and dump in the results after theOffer, I still get offer 3 only.
I get this error message:
TextEdit got an error: NSReceiverEvaluationScriptError: 4
if I don’t make this change to the script.
set strFile to ((aFolder & item i of lstFolderContents) as string) as alias
tell application "TextEdit"
open strFile
tell strFile to set theText to text of document 1 of application "TextEdit"
Could that have anything to do with it?
Okay, I figured it out. It goes back to closing the original textedit document and opening a new textedit document and setting the text of theOffer to the new document. Now it only has that isolated offer to access. It’s running great on all offers now.
tell application "TextEdit"
open strFile
tell strFile
set theText to text of document 1 of application "TextEdit"
end tell
close document 1
make new document
end tell
tell application "TextEdit"
set text of document 1 of application "TextEdit" to theText
end tell
set theOffer to my extractBetween(theText, whichOne, "Offer " & nextNum)
Great. Good luck with it.