Folks- I have a find function which works well when there’s something to be found. When there’s an error, it errors out rather than triggering the ‘on error’ function. Basically, an ITEMCODE is usually on the last page (vpagelength. Occasionally it’s found on the first page. Those are my two conditions. What’s more, it appears to be erroring AFTER the find function, where I have a kludgy method for pulling out the actual itemcode, because the presence of tags in the file result in some ugly non-characters in the string.
here’s the code:
on itemcode()
tell application "Adobe InDesign CS2" -- search function
tell active document
set a to page items of page vpagelength whose class is group --ungroup grouped boxes to allow search feature
repeat with i in a
ungroup i
end repeat
end tell
try
select (every text frame whose contents ≠"") of page vpagelength of active document -- search function
set find preferences to nothing
set change preferences to nothing
set searchResults to search selection for "1.^9^9^9^9^9^9.^9^9^9" -- search function
on error
select (every text frame whose contents ≠"") of page 1 of active document -- search function
set find preferences to nothing
set change preferences to nothing
set searchResults to search selection for "1.^9^9^9^9^9^9.^9^9^9" -- search function
end try
end tell
end itemcode
(*pulls itemcode from document*)
(*kludge to pull actual itemcode and strip null characters*)
to kludge()
if (item 1 of searchResults) ≠{} then -- kludge to pull actual itemcode and ignore null char
set fullcode to ((item 1 of searchResults) as string) -- kludge to pull actual itemcode and ignore null char
else if (item 2 of searchResults) ≠{} then -- kludge to pull actual itemcode and ignore null char
set fullcode to ((item 2 of searchResults) as string) -- kludge to pull actual itemcode and ignore null char
else if (item 3 of searchResults) ≠{} then -- kludge to pull actual itemcode and ignore null char
set fullcode to ((item 3 of searchResults) as string) -- kludge to pull actual itemcode and ignore null char
else if (item 4 of searchResults) ≠{} then -- kludge to pull actual itemcode and ignore null char
set fullcode to ((item 4 of searchResults) as string) -- kludge to pull actual itemcode and ignore null char
else if (item 5 of searchResults) ≠{} then -- kludge to pull actual itemcode and ignore null char
set fullcode to ((item 5 of searchResults) as string) -- kludge to pull actual itemcode and ignore null char
else if (item 6 of searchResults) ≠{} then -- kludge to pull actual itemcode and ignore null char
set fullcode to ((item 6 of searchResults) as string) -- kludge to pull actual itemcode and ignore null char
else if (item 7 of searchResults) ≠{} then -- kludge to pull actual itemcode and ignore null char
set fullcode to ((item 7 of searchResults) as string) -- kludge to pull actual itemcode and ignore null char
else if (item 8 of searchResults) ≠{} then -- kludge to pull actual itemcode and ignore null char
set fullcode to ((item 8 of searchResults) as string) -- kludge to pull actual itemcode and ignore null char
else if (item 9 of searchResults) ≠{} then -- kludge to pull actual itemcode and ignore null char
set fullcode to ((item 9 of searchResults) as string) -- kludge to pull actual itemcode and ignore null char
end if
end kludge
(*kludge to pull actual itemcode and strip null characters*)
here’s the event log history
tell application "Adobe InDesign CS2"
get every page item of page "8" of active document whose class = group
{}
select every text frame of page "8" of active document whose contents ≠""
{}
set find preferences to nothing
set change preferences to nothing
search selection for "1.^9^9^9^9^9^9.^9^9^9"
{{}, {}, {}, {}, {}}
"Can't get item 6 of {{}, {}, {}, {}, {}}."
my questions are- why isn’t the script moving to the on error condition (searching page 1) when it doesn’t find the string? Is that the ugliest kludge ever?
-ralph