Hi all,
I have a XPress file that contains several text boxes. In some of those text boxes, there are some ISBN 10 digits that appears like that :
I have to replace those ISBN by new ones with 13 digits following a known procedure.
Here is my script :
tell application "QuarkXPress Passport"
tell document 1
activate
repeat with i from 1 to (count of text box)
set currentTextBox to text box i
if text of currentTextBox contains "/ ISBN" then
repeat with j from 1 to (count paragraph of currentTextBox)
set currentPar to paragraph j of currentTextBox
if currentPar contains "/ ISBN 2" then
set varslash to "prems"
repeat with k from 1 to (count characters of currentPar)
if character k of currentPar = "/" and varslash = "prems" then
set slashdeb to (k)
set varslash to "deuz"
else if character k of currentPar = "/" and varslash = "deuz" then
set slashfin to (k)
exit repeat
end if
end repeat
set oldISBN10 to text from character (slashdeb + 7) to character (slashfin - 3) of currentPar
set sum to 38 --9*1 + 7*3 + 8*1
set mult to 3
repeat with n from (slashdeb + 7) to (slashfin - 3)
set currentChar to character n of currentPar
if currentChar = "-" then
-- do nothing
else
set sum to sum + (currentChar * mult) as integer
if mult = 1 then
set mult to 3
else
set mult to 1
end if
end if
end repeat
set cle to ((1000 - sum) mod 10) as integer
set ISBN13 to "978-" & (oldISBN10) & (cle)
set text from character (slashdeb) to character (slashfin) of currentPar to ("/ ISBN " & (ISBN13) & " /")
end if
end repeat
end if
end repeat
end tell
end tell
At the beginning if the file, this script worked fine, the ISBN were well replaced.
But after (from the text box n°14 (??)), I had an error on the line
set text from character (slashdeb) to character (slashfin) of currentPar to ("/ ISBN " & (ISBN13) & " /")
that tells me I can’t do that replacement.
And I can’t continue replacing my ISBN, I always get the same error.
Does anyone know why ?
Thanks in advance.
J.
Quark is super-sensitive about putting commands in the correct heirarchy of text goes inside the paragraph tell block which is inside the Tell story 1 block which is inside the tell text box, etc. etc. After a bit of experimenting, I got this to work. Replace the line that was giving you the error with this three line tell block.
Take out:
set text from character (slashdeb) to character (slashfin) of currentPar to ("/ ISBN " & (ISBN13) & " /")
Put this in its place:
tell story 1 of currentTextBox
set (every text where it is (text from character slashdeb to character slashfin of currentPar)) to ("/ ISBN " & (ISBN13) & " /")
end tell
Model: G5 Tower (not Intel) - Script Editor ver 2.1.1
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
Hmmm. I created a test file and created a couple of text boxes with a few dummy numbers in it like “15 € / ISBN 2-1111-22222-3 / code” and the script seem to work just fine. I am not getting the result you describe. Anything else you are doing different?
Model: G5 Tower (not Intel) - Script Editor ver 2.1.1
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
I received your test file and experimented quite a bit to get this script to work, but I can’t get it to work. I am finding that it errors out (error -116) when the text box wraps to page 2. Somehow, having linked text boxes is confusing the paragraph count as it tries to go through one paragraph at a time. Here is the final script I was working on. This worked well for the first page and then it errors out and won’t do anything to page 2.
If any other Quark scripter out there wants to take a shot at making this work, create a document with multiple pages and linked text boxes going across pages with text that includes any dummy ISBN numbers following the format in the above posts. I did try taking out the “enter” key characters that force the text to the next column/page and that did not make a difference. The problem seems to be in the wrap to the next linked text box.
tell application "QuarkXPress"
tell document 1
activate
repeat with i from 1 to (count of text box)
set currentTextBox to text box i
if (text of currentTextBox contains "/ ISBN") then
repeat with j from 1 to (count paragraph of text box i)
if (text of paragraph j of text box i) is not "" then
set currentPar to paragraph j of currentTextBox
if (currentPar contains "/ ISBN") and (currentPar does not contain "ISBN 978-") then
set varslash to "prems"
repeat with k from 1 to (count characters of currentPar)
if character k of currentPar = "/" and varslash = "prems" then
set slashdeb to (k)
set varslash to "deuz"
else if character k of currentPar = "/" and varslash = "deuz" then
set slashfin to (k)
exit repeat
end if
end repeat
set oldISBN10 to text from character (slashdeb + 7) to character (slashfin - 3) of currentPar
set sum to 38 --9*1 + 7*3 + 8*1
set mult to 3
repeat with n from (slashdeb + 7) to (slashfin - 3)
set currentChar to character n of currentPar
if currentChar = "-" then
else
set sum to sum + (currentChar * mult) as integer
if mult = 1 then
set mult to 3
else
set mult to 1
end if
end if
end repeat
set cle to ((1000 - sum) mod 10) as integer
set ISBN13 to "978-" & (oldISBN10) & (cle)
tell story 1 of currentTextBox
set (every text where it is (text from character slashdeb to character slashfin of currentPar)) to ("/ ISBN " & (ISBN13) & " /")
end tell
end if
end if
end repeat
end if
end repeat
end tell
end tell
No problem, Matt. Thanks a lot for trying.
If anyone has an idea, I’m still interested.
Julie
Here is maybe a hint : when I run the script, it fails, let say, page 2 (so page 1 worked). If I remove page 1 and run the script again, it works on the first page (the old second one) and fails on page 2 or 3. If I continue like that, I can do the whole document but it’s not a good solution if the document contains several hundreds of pages… But the problem seems to be related to the number of pages that is treated…
I already tried to unlink the document before running the script but it still fails…