The script that follows produces PDFs. My plan is to let the script make PDFs; if there are errors, such as missing fonts, updated links, missing links, or overset text boxes, it will close the ID file, it will create report log file with the name of file & the type of error, and then continue making PDFs. Making this happen is proving to be challenging. For instance, if I select three ID files with missing fonts, modified links, or overset boxes, and the first one has missing links, the script will proceed with the modified links block, but the file will close and I will receive an execution error since the file is no longer open. I rely heavily on your expertise and whatever assistance you may provide. Thanks
set source_folder to choose file of type "IDdD" with prompt "Select the InDesign files to export as single PDFs" with multiple selections allowed without invisibles
tell application "Finder" to set theFiles to every item of source_folder
set the_choice to {"Smallest File Size", "High Quality Print", "PDF/X-1a", "Press Quality"}
set the_choiceFav to choose from list the_choice with title "PDF Job Options" with prompt "Select a PDF Job Option" default items "Flatten PDF w/o Crop marks"
if the_choiceFav is false then error number -128 (* user cancelled *)
set myPDFpreset to item 1 of the_choiceFav
-- select region
set the_PROOF_choice to {"south", "north", "west", "east", "se", "ne"}
set the_PROOF_choiceFav to choose from list the_PROOF_choice with title "Regions" with prompt "Select a region to add the name to the PDFs" default items (item 1 of the_PROOF_choice)
if the_PROOF_choiceFav is false then error number -128 -- user cancelled
---_______________________
repeat with oneFile in theFiles
tell application id "com.adobe.indesign"
my setUserInteractionLevel() -- no indesign messages
activate
set myDocument to open (oneFile as alias)
tell myDocument
set activeDoc to true
set DocName to name -- this is for the error log file
--Check links +++++++++++++++++
set allLinks to (every link whose status is link out of date)
if (count of ((links whose status contains link missing) as list)) > 0 then
my resetUserInteractionLevel()
say "Missing links found." using "Samantha"
display alert "Missing Links found." buttons {"See Batch Errors Log.txt file on your desktop"} as critical cancel button 1 giving up after 2 --120 --2mins
set TheText to DocName & {tab} & "MISSING links" & return
my write_to_file(TheText, true)
set activeDoc to false
close myDocument saving no
--error number -128
else if (count of ((links whose status contains link out of date) as list)) > 0 then
my resetUserInteractionLevel()
say "Update Modified links." using "Samantha"
display alert "Update Modified Links." buttons {"See Batch Errors Log.txt file on your desktop"} as critical cancel button 1 giving up after 2 --120 --2mins
set TheText to DocName & {tab} & "Modified links" & return
my write_to_file(TheText, true)
set activeDoc to false
close myDocument saving no
--error number -128
end if
--+++++++++++++++++
--Check if there are any text boxes with overset text
set thereIsTextOverflow to ((overflows of parent story of every text frame) contains true)
if thereIsTextOverflow then
my resetUserInteractionLevel()
say "Overset text boxes found." using "Samantha"
display alert "Overset text boxes found.
TIP: Turn on hidden layers and look for overset text boxes." buttons {"OK"} as warning default button 1 giving up after 2 --10secs
set TheText to DocName & {tab} & "Overset text boxes" & return
my write_to_file(TheText, true)
set activeDoc to false
close myDocument saving no
--error number -128 --If user select the button "See Batch Errors Log.txt file on your desktop" it will cancel pero si continua y se expira los segs. hay que poner este error para cancelar el export
end if
--++++++++++++++++++++++
--check missing fonts
set font_list to status of every font -- constants list
if font_list contains not available then -- constant comparsion
my resetUserInteractionLevel()
--display dialog " Missing Font." buttons {"OK"} with icon 0 default button 1 cancel button 1 giving up after 120 --2mins
say "Missing Fonts found." using "Samantha"
display alert "Missing Fonts found." buttons {"See Batch Errors Log.txt file on your desktop"} as critical cancel button 1 giving up after 5
set TheText to DocName & {tab} & "Fonts missing" & return
my write_to_file(TheText, true)
set activeDoc to false
close myDocument saving no
--error number -128
else if font_list contains substituted then
my resetUserInteractionLevel()
--display dialog "A Font has been substituted or it is missing." buttons {"OK"} with icon 0 default button 1 cancel button 1 giving up after 300 --5min
say "A Font has been substituted or it is missing." using "Samantha"
display alert "A Font has been substituted or it is missing." buttons {"See Batch Errors Log.txt file on your desktop"} as critical cancel button 1 giving up after 5
set TheText to DocName & {tab} & "Font substituted or it is missing" & return
my write_to_file(TheText, true)
set activeDoc to false
set dateFormatter to NSDateFormatter's alloc()'s init()
(dateFormatter's setDateFormat:"YY-dd-MM hh:mm:ss")
close myDocument saving no
error number -128
end if
---_______________________
end tell --myDocument
set source_folder to file path of myDocument
set theName to name of myDocument
set text item delimiters of AppleScript to {"_"}
set theShortName to text 1 thru text item -2 of theName
--text 1 thru text item -2 is every character from the first character to the second to last text item
set text item delimiters of AppleScript to ""
tell application "Finder"
if (exists folder "PDF" of folder source_folder) is false then
make folder at source_folder with properties {name:"PDF"}
end if
end tell
tell application id "com.adobe.indesign"
set pagesCount to count pages of myDocument
tell me to set progress total steps to pagesCount --progress total steps. the number of steps needed to complete this task.
repeat with x from 1 to pagesCount
tell me to set progress description to "Page " & x & " of " & pagesCount --progress description. Text describing this task.
tell me to activate
set thePageName to name of page x of myDocument
set page range of PDF export preferences to thePageName
--section number must have 3 digits
set threeDigitPageName to text -3 thru -1 of ("00" & thePageName)
--text -3 thru -1 are the last 3 characters*)
set theFilePath to source_folder & "PDF:" & theShortName & "_" & threeDigitPageName & "_" & the_PROOF_choiceFav & ".pdf" as string
--EXPORT PDF
tell myDocument
with timeout of 600 seconds --10mins
export format PDF type to theFilePath using myPDFpreset without showing options
repeat -- repeat until current export is finished
try
delay 1
alias theFilePath
exit repeat
end try
end repeat
end timeout
end tell
tell me to set progress completed steps to x --progress completed steps. The number of steps of the task that have been completed so far.
end repeat -- with x
end tell
close myDocument saving no
my resetUserInteractionLevel()
--====
end tell
end repeat
on setUserInteractionLevel()
tell application id "com.adobe.indesign"
set user interaction level of script preferences to never interact
end tell
end setUserInteractionLevel
on resetUserInteractionLevel()
tell application id "com.adobe.indesign"
set user interaction level of script preferences to interact with all
end tell
end resetUserInteractionLevel
on write_to_file(this_data, append_data)
try
set the log_file to (path to desktop as text) & "Batch Errors Log.txt" as text
set the open_target_file to open for access file log_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file log_file
end try
return false
end try
end write_to_file
beep 6