I am trying to remove text boxes from a number of quark documents where the first word of the text is white. Here is the code that I have tried but I can’t figure out where it’s going wrong.
tell application "QuarkXPress"
activate
tell front document
set tool mode to drag mode
set deleted to 0
set tot to count of every text box
repeat with i from tot to 1 by -1
set deleted to deleted + 1
try
if color of first word of text box i is "White" then
delete text box i
end if
end try
end repeat
display dialog "Total of " & deleted & " text boxes
has been deleted successfully." buttons {"OK"} default button 1
end tell
end tell
Running on a test document with two text boxes, one of which has the first word coloured white I get this reply returned by applescript:
tell application "QuarkXPress"
activate
set tool mode of document 1 to drag mode
count every text box of document 1
--> 2
get color of word 1 of text box 2 of document 1
--> color spec "Black" of document "Project1"
color spec "Black" of document "Project1" = "White"
--> error number -1708
get color spec "Black" of document "Project1"
--> color spec "Black" of document "Project1"
get color of word 1 of text box 1 of document 1
--> color spec "White" of document "Project1"
display dialog "Total of 2 text boxes
has been deleted successfully." buttons {"OK"} default button 1
--> {button returned:"OK"}
end tell
Result:
{button returned:"OK"}
It reports that two boxes will be deleted, it should only be one and it actually deletes none, can anyone help please.
tell application "QuarkXPress"
tell page 1 of layout space 1 of project 1
set allTheTextBoxes to every text box
repeat with thisItem from (count of allTheTextBoxes) to 1 by -1
set firstWord to word 1 of story 1 of item thisItem of allTheTextBoxes
if firstWord = "White" then
delete item thisItem of allTheTextBoxes
end if
end repeat
end tell
end tell
Haven’t tested it too thoroughly.
You’ll need to add to looping for all the pages in each document, and then for every document.
I didn’t make my description in my original post clear enough it read okay to myself when reading it back, what I am trying to do is remove every box where the first word in that box is coloured white, not that the word is white.
I have since tried a different approach and I am now trying to remove the boxes using the character sheet that is applied to the first word, but I am still working on it, so any further help would be appreciated.
Thanks again, and sorry for my confusing first post, hopefully this has made things a little clearer.
tell application "QuarkXPress9"
tell document 1
repeat with i from (count of text boxes) to 1 by -1
try
if name of color of (word 1 of story 1 of text box i) is "White" then
delete text box i
end if
end try
end repeat
end tell
end tell
.which is shorter
I did think about that but remembered I came accross issues in the past targetting every objects so I gave up before even giving a shot.
It was a nice little exercise. Having played around with object references I tried reducing it down as far as I could.
Didn’t know about the issues though.
I tested the code on a document containing a few pages with a number of text boxes on each.
I even went as far as to put a text box on the master page which carried through to all the others.
The relevant boxes were deleted when the code was executed.