My problem was that I presumed the getting an index, which starts at zero, had to be used throughout. Seeing your example set me straight.
I also found the command ‘selectobjectsonactiveartboard did not select my new text boxes, only artwork, so I had to write handlers to get the rectangle of every object on each Artboard (see code for posterity).
property actualPrintableJobsCounter : 0
property theItem : ((path to desktop) & "Adore Plate.ai" as text) # as alias
property tempName : ""
property tempNameExtension : ""
property didItPrint : false
property errorMessage : ""
property sayEveryErrorMessage : true
property runForOZ : true
property voiceSetter : "Vicki"
property theLargePagePrinter : "Large Page Printer"
property PreserveFileName : ""
property theJobsTally : 0
property ftpPrintFlag : false
property mailReadyToSend : false
property extensionName : ""
property saveftpFiles : true
property attachmentBarCodeDateTimeName : "(2015-07-05 121212"
property preFlightpdfList : {}
my printIllustrator()
on printIllustrator()
try
set p to 1
tell application "Finder"
set my tempName to name of file (my theItem) as text
set my PreserveFileName to tempName
end tell
tell application id "com.adobe.illustrator" -- Adobe Illustrator
try
activate
repeat until the (count of documents) is 0
close every document saving no
end repeat
set addBarCode to false
set my theItem to my theItem as alias
try
tell application "System Events" to tell process "Adobe Illustrator"
try
keystroke return
end try
end tell
open my theItem dialogs no -- as alias (don't use 'as alias' or routine won't work)
end try
repeat 2 times
tell application "System Events" to tell process "Adobe Illustrator"
try
click button "Continue" of window 1
end try
try
keystroke return
end try
end tell
end repeat
set x to 0
set foundAFile to false
repeat
if exists document 1 then
set foundAFile to true
exit repeat
end if
do shell script ("sleep 0.2")
set x to x + 1
if x ≥ 400 then exit repeat --try for 40 seconds
end repeat
set addBarCode to false
tell document 1
set n to number of layers
repeat with x from 1 to n
set p to 5
set locked of layer x to false
end repeat
end tell
if my tempName does not contain "_UEI " then set addBarCode to true
set p to 2
if addBarCode then
tell document 1
set p to 2.01
set artBoardCount to count of artboards
end tell
set p to 2.02
repeat with eachArtBoardCounter from 1 to artBoardCount
try
set TempAttachmentName to my ResetAttachmentName()
set eachArtBoard to eachArtBoardCounter
set p to 2.1
# my doFoo(eachArtBoard - 1)
set p to 2.12
do shell script ("sleep 1")
# tell document 1 to tell artboard
set p to 2.14
tell document 1
set {x1, y1, x2, y2} to artboard rectangle of artboard eachArtBoardCounter
set xleft to x2
set ytop to y2
set xright to x1
set ybottom to y1
repeat with eachItem in page items
set theBounds to visible bounds of eachItem
set x3 to item 1 of item 1 of theBounds
set y3 to item 2 of item 1 of theBounds
set x4 to item 3 of item 1 of theBounds
set y4 to item 4 of item 1 of theBounds
if x3 < xleft and x3 ≥ x1 then set xleft to x3
if y3 > ytop and x3 > x1 and x4 < x2 then set ytop to y3
if x4 > xright and x4 ≤ x2 then set xright to x4
if y4 < ybottom and x3 > x1 and x4 < x2 then set ybottom to y4
end repeat
set p to 2.6
set bb to {xleft, ytop, xright, ybottom}
end tell
# end tell
set p to 2.7
#set bb to visible bounds of selection
set p to 4
#
# Text Frame 1
#
make new text frame in document 1 with properties {name:"AreaText", contents:TempAttachmentName, position:{((item 1 of bb) + 2), ((item 2 of bb) + 30)}}
set p to 6.1
try
make new character style in document 1 with properties {name:"BarCodeBox"}
end try
set p to 6.2
set the size of character style "BarCodeBox" of document 1 to 10
set p to 6.3
apply character style character style "BarCodeBox" of document 1 to the text range of text frame "AreaText" of document 1
set p to 6.4
set the text font of text range of text frame "AreaText" of document 1 to text font "IDAutomationHC39M"
#
# Text Frame 2
#
make new text frame in document 1 with properties {name:"AreaTextTwo", contents:my PreserveFileName, position:{((item 1 of bb) + 240), ((item 2 of bb) + 30)}}
set p to 7.1
try
make new character style in document 1 with properties {name:"NameBox"}
end try
set p to 7.2
set the size of character style "NameBox" of document 1 to 16
set p to 7.3
apply character style character style "NameBox" of document 1 to the text range of text frame "AreaTextTwo" of document 1
set p to 7.4
set the text font of text range of text frame "AreaTextTwo" of document 1 to text font "Cochin"
# set bb to crop marks of document 1
set p to 8
# tell document 1 to set bbb to the artboard rectangle of artboard eachArtBoard
tell document 1
repeat with eachItem in page items
set theBounds to visible bounds of eachItem
set x3 to item 1 of item 1 of theBounds
set y3 to item 2 of item 1 of theBounds
set x4 to item 3 of item 1 of theBounds
set y4 to item 3 of item 1 of theBounds
if x3 < xleft and x3 ≥ x1 then set xleft to x3
if y3 > ytop and x3 > x1 and x4 < x2 then set ytop to y3
if x4 > xright and x4 ≤ x2 then set xright to x4
if y4 < ybottom and x3 > x1 and x4 < x2 then set ybottom to y4
end repeat
end tell
set p to 2.6
set bbb to {xleft, ytop, xright, ybottom}
set p to 9
tell document 1 to set artboard rectangle of artboard eachArtBoard to bbb
on error errmsg number errnum
set my didItPrint to false
tell application "System Events" to display dialog "printIllustrator CC 2015 " & return & errmsg & return & "number " & errnum & " p = " & p giving up after 40
end try
end repeat
end if
set p to 16
on error errmsg number errnum
set my didItPrint to false
tell application "System Events" to display dialog "printIllustrator " & return & errmsg & return & "number " & errnum & " p = " & p giving up after 40
end try
try
activate
do shell script ("sleep 1")
tell application "System Events" to tell process "Adobe Illustrator"
keystroke "p" using command down
do shell script ("sleep 0.4")
end tell
repeat 18 times
tell application "System Events" to tell process "Adobe Illustrator"
keystroke tab
end tell
do shell script ("sleep 0.05")
end repeat
tell application "System Events" to tell process "Adobe Illustrator"
do shell script ("sleep 0.1")
keystroke (characters 1 through -1 of (my theLargePagePrinter as text)) as text
# do shell script ("sleep 0.1")
# keystroke tab
# keystroke (characters 1 through -1 of (my theLargePagePrinter as text)) as text
do shell script ("sleep 0.2")
keystroke return
try
keystroke return
end try
end tell
end try
do shell script ("sleep 0.5")
end tell
set my theJobsTally to (my theJobsTally) + 1 # Add to printed jobs Tally
#my RenameAttachment(my theItem , TempAttachmentName)
if addBarCode then
if my saveftpFiles then
#tell application "Adobe Illustrator" to set my tempName to name of document 1
set newPath to my setUpSavePath("_UEI ftpSaving") as text
tell application "Adobe Illustrator"
try
save document 1 in file newPath
end try
end tell
set end of my preFlightpdfList to newPath
if my ftpPrintFlag then set my mailReadyToSend to true
end if
end if
# set my didItPrint to true
tell application "Adobe Illustrator"
repeat until the (count of documents) is 0
close every document saving no
end repeat
end tell
on error errmsg number errnum
set my didItPrint to false
my sayTheText("illustrator error")
if errnum = -1728 then
set my errorMessage to my errorMessage & "We struck an Illustrator file that refused to open." & return & "It might be that fonts were missing." & return
if DialogFlag > 0 then set my errorMessage to my errorMessage & "There were " & DialogFlag & " opening dialogs." & return & return
end if
tell application "System Events" to display dialog "printIllustrator " & errmsg & return & errnum giving up after 40
tell application "Adobe Illustrator"
repeat until the (count of documents) is 0
close every document saving no
end repeat
end tell
end try
end printIllustrator