Hello,
I have a script that converts InDesign docs to PDF’s, using a custom setting that I made.
If images or a typeface is missing, it does let the user know, but within a few seconds, it makes the PDF regardless.
Is there a way to stop the script when the error occurs, giving the user the chance to load the images and fonts, and then have the other files continue?
Or worse case scenario, stop the script entirely.
Thanks!
babs
property Babs_Folder : "Babs PDF Folder"
global deskPath
global PathToFolder
global PathToFolder2
global tempPictures
on open thefiles
tell application "Finder"
activate
set tempPictures to (every item of (get selection)) -- MUST GET BEFORE MAKING FOLDERS
if not (exists folder Babs_Folder) then make new folder with properties {name:Babs_Folder}
set deskPath to desktop as text
set PathToFolder to POSIX path of (deskPath & Babs_Folder)
set PathToFolder2 to deskPath & Babs_Folder & ":"
end tell
my openfiles()
say "Finished"
end open
on openfiles()
try
tell application "Finder"
repeat with LoopFiles in tempPictures
set foundImages to {}
if kind of LoopFiles = "Folder" then
try
set foundImages to files of entire contents of LoopFiles as list
on error
set foundImages to files of entire contents of LoopFiles
end try
else
if kind of LoopFiles is not in {"Volume", "Disk Image", "Application", "Web Internet Location", "Document", "Text Clipping"} then
set end of foundImages to LoopFiles
end if
end if
--set WorkingFile to item i of fileList
repeat with WorkingFile in foundImages
if not ((kind of WorkingFile starts with "Quark") or (kind of WorkingFile starts with "InDesign")) then
activate
display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 1
else
--Determine whether to use InDesign subroutines or Quark subroutines
if (kind of WorkingFile starts with "InDesign") then -- Process as InDesign
my createInDesignPDF(WorkingFile, PathToFolder2)
else -- Process as Quark
my createQuarkPDF(WorkingFile)
end if
end if
end repeat
end repeat
end tell
on error errmsg
display dialog "OpenFiles." & return & errmsg giving up after 20
end try
end openfiles
on createInDesignPDF(WorkingFile, savePath)
set x to 0
repeat
if x = 0 then
set newpart to ""
else
set newpart to " " & x
end if
tell application "Finder"
set tempname to my add_extension(WorkingFile, newpart, "pdf")
if not (exists file tempname in folder Babs_Folder) then exit repeat
end tell
set x to x + 1
end repeat
tell application "Adobe InDesign CS5.5"
try
try
--set user interaction level of script preferences to never interact
end try
open WorkingFile as alias
delay 2
repeat
if exists document 1 then exit repeat
delay 0.2
end repeat
set theProps to properties of PDF export preset "Babs Setting"
set newProps to {view PDF:false, crop marks:false, bleed marks:false, color bars:false, registration marks:false} & theProps
set oldProps to properties of PDF export preferences
set properties of PDF export preferences to newProps
export front document format PDF type to (savePath & tempname) without showing options
set properties of PDF export preferences to oldProps
delay 1
tell documents to close saving no
try
set user interaction level of script preferences to interact with all
end try
on error errmsg
display dialog "CreateIndesignPDF." & return & errmsg giving up after 20
end try
end tell
end createInDesignPDF
on createQuarkPDF(WorkingFile)
try
set x to 0
repeat
if x = 0 then
set newpart to ""
else
set newpart to " " & x
end if
tell application "Finder"
set tempname to my add_extension(WorkingFile, newpart, "pdf")
if not (exists file tempname in folder Babs_Folder) then exit repeat
end tell
set x to x + 1
end repeat
tell application "QuarkXPress"
activate
open WorkingFile as alias
tell application "System Events" to tell process "QuarkXPress"
click menu item "Layout as PDF..." of menu 1 of menu item "Export" of menu 1 of menu bar item "File" of menu bar 1
delay 1
keystroke tempname
delay 1
keystroke "G" using {shift down, command down}
delay 1
keystroke PathToFolder
delay 1
click button "Go" of sheet 1 of window "Export as PDF"
end tell
repeat 2 times
delay 1
activate
tell application "System Events" to tell process "QuarkXPress"
try
if exists button "OK" of window 1 then
click button "OK" of window 1
end if
end try
end tell
end repeat
delay 1
tell application "System Events" to tell process "QuarkXPress"
try
click button "Save" of window "Export as PDF"
end try
end tell
repeat 4 times
delay 1
activate
tell application "System Events" to tell process "QuarkXPress"
try
if exists button "OK" of window 1 then
click button "OK" of window 1
end if
end try
try
if exists button "List Profiles" of window 1 then
click button "Continue" of window 1
end if
end try
end tell
end repeat
delay 2
close front document saving no
end tell
on error errmsg
display dialog "CreateQuarkPDF." & return & errmsg giving up after 20
end try
end createQuarkPDF
on add_extension(WorkingFile, new_part, new_extension)
try
set this_info to info for WorkingFile as alias
set this_name to the name of this_info
set this_extension to the name extension of this_info
if this_extension is missing value then
set the default_name to this_name
else
set the default_name to text 1 thru -((length of this_extension) + 2) of this_name
end if
return (the default_name & new_part & "." & the new_extension)
on error errmsg
display dialog "add extension " & return & errmsg
end try
end add_extension
hi
I should have been more clear…
It’s only the In Design part I am worried about. Not the Quark part!!!
Thanks!!!
babs
Hi, Barbara.
The PDF continues its generation because the error trapping is mistimed. If there are missing graphics and/or fonts, the application should warn you on open, so that’s where the trapping is really needed. You can remove the try blocks around the user interaction level statements.
This would stop the script:
on error
Error number -128
end
–edited for grammar
Hi Marc,
Thanks…I won’t be able to try this till Monday, as I am running 10.8 at home and the scripts don’t work on 10.8. We have 10.5 at work, so I can test it there once I’m back. This is what I did as far as removing the try statements, I hope I removed the right ones. My question is, do I need to add this error statement to my script? Or is this the error I should see once I run it.
Thank so much!!!
Babs
property Babs_Folder : "Babs PDF Folder"
global deskPath
global PathToFolder
global PathToFolder2
global tempPictures
on open thefiles
tell application "Finder"
activate
set tempPictures to (every item of (get selection)) -- MUST GET BEFORE MAKING FOLDERS
if not (exists folder Babs_Folder) then make new folder with properties {name:Babs_Folder}
set deskPath to desktop as text
set PathToFolder to POSIX path of (deskPath & Babs_Folder)
set PathToFolder2 to deskPath & Babs_Folder & ":"
end tell
my openfiles()
say "Finished"
end open
on openfiles()
try
tell application "Finder"
repeat with LoopFiles in tempPictures
set foundImages to {}
if kind of LoopFiles = "Folder" then
try
set foundImages to files of entire contents of LoopFiles as list
on error
set foundImages to files of entire contents of LoopFiles
end try
else
if kind of LoopFiles is not in {"Volume", "Disk Image", "Application", "Web Internet Location", "Document", "Text Clipping"} then
set end of foundImages to LoopFiles
end if
end if
--set WorkingFile to item i of fileList
repeat with WorkingFile in foundImages
if not ((kind of WorkingFile starts with "Quark") or (kind of WorkingFile starts with "InDesign")) then
activate
display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 1
else
--Determine whether to use InDesign subroutines or Quark subroutines
if (kind of WorkingFile starts with "InDesign") then -- Process as InDesign
my createInDesignPDF(WorkingFile, PathToFolder2)
else -- Process as Quark
my createQuarkPDF(WorkingFile)
end if
end if
end repeat
end repeat
end tell
on error errmsg
display dialog "OpenFiles." & return & errmsg giving up after 20
end try
end openfiles
on createInDesignPDF(WorkingFile, savePath)
set x to 0
repeat
if x = 0 then
set newpart to ""
else
set newpart to " " & x
end if
tell application "Finder"
set tempname to my add_extension(WorkingFile, newpart, "pdf")
if not (exists file tempname in folder Babs_Folder) then exit repeat
end tell
set x to x + 1
end repeat
tell application "Adobe InDesign CS5.5"
try
--set user interaction level of script preferences to never interact
open WorkingFile as alias
delay 2
repeat
if exists document 1 then exit repeat
delay 0.2
end repeat
set theProps to properties of PDF export preset "Babs Setting"
set newProps to {view PDF:false, crop marks:false, bleed marks:false, color bars:false, registration marks:false} & theProps
set oldProps to properties of PDF export preferences
set properties of PDF export preferences to newProps
export front document format PDF type to (savePath & tempname) without showing options
set properties of PDF export preferences to oldProps
delay 1
tell documents to close saving no
set user interaction level of script preferences to interact with all
on error errmsg
display dialog "CreateIndesignPDF." & return & errmsg giving up after 20
end try
end tell
end createInDesignPDF
on createQuarkPDF(WorkingFile)
try
set x to 0
repeat
if x = 0 then
set newpart to ""
else
set newpart to " " & x
end if
tell application "Finder"
set tempname to my add_extension(WorkingFile, newpart, "pdf")
if not (exists file tempname in folder Babs_Folder) then exit repeat
end tell
set x to x + 1
end repeat
tell application "QuarkXPress"
activate
open WorkingFile as alias
tell application "System Events" to tell process "QuarkXPress"
click menu item "Layout as PDF..." of menu 1 of menu item "Export" of menu 1 of menu bar item "File" of menu bar 1
delay 1
keystroke tempname
delay 1
keystroke "G" using {shift down, command down}
delay 1
keystroke PathToFolder
delay 1
click button "Go" of sheet 1 of window "Export as PDF"
end tell
repeat 2 times
delay 1
activate
tell application "System Events" to tell process "QuarkXPress"
try
if exists button "OK" of window 1 then
click button "OK" of window 1
end if
end try
end tell
end repeat
delay 1
tell application "System Events" to tell process "QuarkXPress"
try
click button "Save" of window "Export as PDF"
end try
end tell
repeat 4 times
delay 1
activate
tell application "System Events" to tell process "QuarkXPress"
try
if exists button "OK" of window 1 then
click button "OK" of window 1
end if
end try
try
if exists button "List Profiles" of window 1 then
click button "Continue" of window 1
end if
end try
end tell
end repeat
delay 2
close front document saving no
end tell
on error errmsg
display dialog "CreateQuarkPDF." & return & errmsg giving up after 20
end try
end createQuarkPDF
on add_extension(WorkingFile, new_part, new_extension)
try
set this_info to info for WorkingFile as alias
set this_name to the name of this_info
set this_extension to the name extension of this_info
if this_extension is missing value then
set the default_name to this_name
else
set the default_name to text 1 thru -((length of this_extension) + 2) of this_name
end if
return (the default_name & new_part & "." & the new_extension)
on error errmsg
display dialog "add extension " & return & errmsg
end try
end add_extension
Hi, again. The example was to be worked into your code, in order to stop it from proceeding. It would replace your current error statement within the createInDesignPDF handler. That said, I looked at your problem a little more thoroughly, and I believe I misassessed it as a timing issue. Allowing interaction does display InDesign’s internal error message, however, that doesn’t actually register as an error to AS, so trapping it is a nonstarter. You need to have an if condition to ensure that all is well, then export.
Something along these lines would work:
if (all graphics's item link's status contains link missing) or (fonts's status contains not available) then
error number -128
else
--export commands
end if
–edited for typo
Hi Marc,
That makes sense…I will see of I can figure what to place in that if statement that would stop the script at that point.
thanks!
babs