I’m trying to transfer text from Quark 5 documents to Filemaker 3 records under OS 9.2 with Applescript 1.8.3 and the text arrives truncated in Filemaker. Text longer than 4060 characters is truncated to 4060. Something in Applescript knows the text’s length but the text in the variable ‘mytext’ is always truncated. Applescript documentation states that there is no limit on the length of a string other than available memory. The text I’m working with is about 17k in length, which isn’t too bad.
Manual operation, copy and paste, works fine but it’s boring and time consuming.
This is driving me bananas. Here is the code I’m having trouble with:
tell application "QuarkXPressâ„¢"
repeat with myDocument from 1 to count of documents
repeat with myStory from 1 to count of stories of document myDocument
set mytext to (text of story myStory of document myDocument)
--- debugging - script knows that story is longer than 4060 characters
--- but mytext is always truncated to 4060
display dialog "story: " & (length of text of story myStory of document myDocument) as string
display dialog "mytext: " & (length of mytext) as string
if length of mytext is greater than 12 then --- ignore artifacts
---select text of story myStory of document myDocument --- copy/paste won't work - crashes
---try
---copy
---end try
tell application "FileMaker Pro"
create new record
---try --- copy/paste won't work. crashes
---paste
---end try
set (cell 5 of last record) to mytext
end tell
end if
end repeat
end repeat
end tell
I don’t script Quark, and I’m in OS X - but I noticed that you haven’t had any takers on this yet, Hack.
I’m only guessing here, but it looks like the 4060 limit might (for some unfathomable reason) be imposed by Quark 5. I was therefore wondering if you could extract the text from Quark in chunks, and then put it together in AppleScript. You’ll probably have to figure out the precise syntax for yourself, but here’s the gist of what I mean, FWIW:
property maxLen : 4000
tell application "QuarkXPressâ„¢"
repeat with myDocument from 1 to count documents
repeat with myStory from 1 to count stories of document myDocument
set textCount to count (text of story myStory of document myDocument)
if textCount > 12 then -- ignore artifacts
if textCount > maxLen then
set myText to {}
repeat with n from 1 to (textCount - maxLen) by maxLen
set myText's end to (text of story myStory of document myDocument)'s text n thru (n + maxLen - 1)
end repeat
set n to n + maxLen
if textCount ≥ n then set myText's end to (text of story myStory of document myDocument)'s text n thru textCount
set text item delimiters to {""} (* precautionary measure *)
tell myText to set myText to beginning & rest
else
set myText to (text of story myStory of document myDocument)
end if
tell application "FileMaker Pro"
create new record
set (cell 5 of last record) to myText
end tell
end if
end repeat
end repeat
end tell
I tried your script in XPress 6.1 Passport and it does not result in the size difference.
Anyway, you might wanna try the use paragraphs:
tell application "QuarkXPress Passport"
repeat with myDocument from 1 to count of documents
repeat with myStory from 1 to count of stories of document myDocument
repeat with myParagraph from 1 to count of paragraphs of story myStory of document myDocument
set mytext to (text of paragraph myParagraph of story myStory of document myDocument)
display dialog "story: " & (length of text of paragraph myParagraph of story myStory of document myDocument) as string
display dialog "mytext: " & (length of mytext) as string
-- do your things with mytext here
end repeat
end repeat
end repeat
end tell
But… You might run into the same problem if a paragraph is bigger than 4060 characters!
Thanks so much for your responses. Am covered up with other stuff for awhile but will get back to this and let you know how it turns out. More later…
John, I modified your suggestion slightly and achieved the desired end (getting all the text of the Quark story into the variable myText). What worked was:
set myText to (paragraphs of story … of textbox … of document …) as text
It would be interesting to see what happens if a story is longer than 4060 paragraphs. hmmmm.
Thanks an an attaboy for the kickstart.
I haven’t tried Kai’s suggestion yet but will be back with results.