I finally handle the loop using a list repeat. Now I’m trying the same trick to run the script in all layouts of each project, but the command “set layoutList to name of every layout space of document theProject” doesn’t work.
Any clue? Thanks!
tell application "QuarkXPress"
activate
set openProjectList to name of every project
repeat with theProject in openProjectList
tell document theProject
set view scale to fit spread in window
set horizontal measure to millimeters
set vertical measure to millimeters
set nameOfDoc to name
set {atid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, space}
set theFolios to text item 1 of nameOfDoc
set AppleScript's text item delimiters to "-"
set folioLeft to (text item 1 of theFolios) - "0"
set folioRight to (text item 2 of theFolios) - "0"
set AppleScript's text item delimiters to atid
set listOfBoxes to every text box
repeat with thisBox in listOfBoxes
set thisBoxBounds to bounds of thisBox as list
set {T, L, B, R} to {(item 1 of thisBoxBounds coerce to real) as integer, (item 2 of thisBoxBounds coerce to real) as integer, (item 3 of thisBoxBounds coerce to real) as integer, (item 4 of thisBoxBounds coerce to real) as integer, story 1 of thisBox}
-- display dialog "T:" & T & " L:" & L & " B:" & B & " R:" & R -- check box position
if T > 223 and L < 8 then
show thisBox
set story 1 of thisBox to folioLeft
else if T > 223 and L > 155 then
set story 1 of thisBox to folioRight
end if
end repeat
end tell
end repeat
end tell
That’s what I told you: or you target a document or you target a layout space not in a document but in a project.
Reading the application dictionary will enlighten you on such subtleties. It’s a kind of path for commands: some of the commands in AS must be addressed to specific objects and not others. Knowing that will help you tremendously (talking to myself as well!). So many times I hit a wall just because I’m not addressing commands to the right objects! HTH.
The wrong thing is that you manipulate the variable i or n when it’s not needed at all. The loop is doing what you wish to accomplish on the other hand: repeat with n from 1 to 10 will have the variable set to 1 at the beginning and then to 2, to 3, etc. on every turn; if you add in that loop set n to n + 1, instead of 2 on the second turn, it’ll be 2 + 1, then at the third turn, 3 + 1, etc. so that you step over a document every single loop. Does this make sense?
Try this instead (unless the variable i is need for sth else):
tell application "QuarkXPress"
activate
set numberProjects to count of projects -- pay attention here: projects contain layout spaces, documents not; if telling projects, you'll want to add layout spaces
repeat with n from 1 to numberProjects
-- here goes the original script
show text box 1 of document n -- here, you're not targetting projects but documents!!! if you do have several layout spaces, you'll want to say text box 1 of layout space 1 of project 1, and you should loop in as many layout spaces inside of a given project.
select text box 1 of document n
set x to name of document n
display dialog "Document " & n & ", Filename " & x
-- here goes the original script
end repeat
end tell