David: In Case You're Bored Enough...
to be interested, I've enhanced, cleaned up, and commented on the Applescript code I posted earlier. The process now only requires 1 user interaction in the case of a full page sized file, and in that case all that is required is a 5 digit number. My next step will probably be to set up some better font handling. Or, I could just set us up the bomb.
tell application "Adobe InDesign CS2"
--Bring InDesign to the front
activate
set thisDocument to active document
tell thisDocument
--Get page information
set myPageTotal to pages per document of document preferences
set myPageHeight to page height of document preferences
set myPageWidth to page width of document preferences
--Set print preset
tell print preferences of thisDocument
set printer to postscript file
set PPD to "Prinergy Refiner"
--General
set reverse order to false
set print spreads to false
set print master pages to false
set print nonprinting to false
set print blank pages to true
--Setup
set paper size to custom
set print page orientation to portrait
set paper height to myPageHeight + 1
set paper width to myPageWidth + 1
set paper offset to 0
set paper gap to 0
set paper transverse to false
set scale mode to scale width height
set scale width to 100
set scale height to 100
set scale proportional to true
set page position to centered
set thumbnails to false
set tile to false
--Marks and Bleed
set crop marks to true
set registration marks to true
set bleed marks to false
set color bars to false
set page information marks to false
set mark type to default
set mark line weight to p25pt
set mark offset to "0.1667 in"
set use document bleed to print to false
set bleed top to "0.125 in"
set bleed inside to "0.125 in"
set bleed bottom to "0.125 in"
set bleed outside to "0.125 in"
set include slug to print to false
--Output
set color output to composite CMYK
set flip to none
set simulate overprint to false
--Graphics
set send image data to optimized subsampling
set font downloading to complete
set PostScript level to level 3
set data format to ASCII
set download PPD fonts to true
--Advanced
set OPI image replacement to false
set omit EPS to false
set omit PDF to false
set omit bitmaps to false
set flattener preset name to "[High Resolution]"
set ignore spread overrides to false
end tell
--Determines which job folder the document is in based on it's links
set AdFolder to file path of link 1 as alias
set ExistingLinks to AdFolder as text
--If the link is in a folder titled "_Links" then we can assume that the folder has already been organized by this script, and use the currently existing document file path. If not, then the job folder will be the folder in which the link exists.
if ExistingLinks does not contain "_Links" then
set OrganizeOrNot to "Organize" as text
set StupidName to name of link 1
set AdFolder to my myReplace(AdFolder, StupidName, "")
set AdFolder to AdFolder as alias
else
set OrganizeOrNot to "Not" as text
set AdFolder to file path of thisDocument
set AdFolder to AdFolder as alias
end if
--Determines how many links are in the document for use in the link move and relink loop below
set TotalLinks to count of links
end tell
--This file will be moved to the "_Support Files" folder while we are working and deleted in the end, as a new version will be saved in the "_Documents" folder.
set DoomedFile to name of thisDocument as text
end tell
--This is the path that will organize the job folder.
if OrganizeOrNot is "Organize" then
tell application "Finder"
--Uses the name of the folder for the final file name of the .indd and .pdf files.
set DocName to name of AdFolder as text
set GenericName to DocName
set AdFolder to AdFolder as text
--This creates the internal folders and saves their paths as text to a variable.
set SupportFolder to make new folder in folder AdFolder with properties {name:"_Support Files"}
set SupportFolder to SupportFolder as text
--Puts everything inside the job folder besides a font folder named "_Fonts" (renaming currently required by user) into the "_Support Files" folder.
move (items in folder AdFolder where name is not "_Support Files" and name is not "_Fonts") to folder SupportFolder
set LinksFolder to make new folder in folder AdFolder with properties {name:"_Links"}
set LinksFolder to LinksFolder as text
set DocumentFolder to make new folder in folder AdFolder with properties {name:"_Document"}
set DocumentFolder to DocumentFolder as text
--This loop will move all images linked within the document to the newly created "_Links" folder and redirect the document links to the new location.
repeat with i from 1 to TotalLinks
tell application "Adobe InDesign CS2"
activate
--Gets the current link location.
tell thisDocument
set thisLink to link i
set LinkName to name of thisLink
set LinkPath to SupportFolder&LinkName
end tell
end tell
--Moves the current link to the "_Links" folder.
tell application "Finder"
move file LinkPath to folder LinksFolder
set FinalLink to LinksFolder&LinkName
end tell
--Redirects the document's link.
tell application "Adobe InDesign CS2"
tell thisDocument
relink thisLink to FinalLink
end tell
end tell
end repeat
end tell
tell application "Adobe InDesign CS2"
tell thisDocument
--Checks for standard full page size to determine whether or not job number should be incorporated into filename.
if myPageWidth is 8.375 and myPageHeight is 10.875 then
set FullOrNot to "Yes"
else
set FullOrNot to "No"
end if
--Both paths will set DocName to the final .indd filename.
if FullOrNot is "Yes" then
set JobNumber to (display dialog "Enter your 5 digit job number" default answer "")
set JobNumber to (text returned of result)
set DocName to JobNumber&" "&DocName&".indd" as text
else if FullOrNot is "No" then
set DocName to DocName&".indd" as text
end if
--Saves the document to the "_Document" folder.
set DocPath to DocumentFolder&DocName
save thisDocument to DocPath
end tell
tell application "Adobe InDesign CS2"
--Updates the variable to the new file name
set thisDocument to active document
--Prints the .ps file to the job folder
tell thisDocument
set PSName to AdFolder&JobNumber&" "&GenericName&".ps"
tell print preferences of thisDocument
set print file to PSName
end tell
print PSName without print dialog
end tell
end tell
end tell
else if OrganizeOrNot is "Not" then
tell application "Adobe InDesign CS2"
activate
save thisDocument
--Works with the known and existing folder structure to set up the file names.
set OrganizedPath to file path of thisDocument as string
set PDFFilePath to my myReplace(OrganizedPath, "_Document:", "")
set GenericName to name of thisDocument as string
set GenericName to my myReplace(GenericName, ".indd", "")
tell application "Adobe InDesign CS2"
tell thisDocument
set PSName to PDFFilePath&GenericName&".ps"
tell print preferences of thisDocument
set print file to PSName
end tell
print PSName without print dialog
end tell
end tell
end tell
end if
--Sets the variable PDFName to the name of the final PDF
set PDFName to my myReplace(PSName, ".ps", ".pdf")
--Sets the variable DistillerError to the name of the Distiller .log file produced in an error
set DistillerError to my myReplace(PSName, ".ps", ".log")
--Deletes an existing PDF or .log file in the job folder and then waits for the .ps file to be created.
tell application "Finder"
if file PDFName exists then delete file PDFName
if file DistillerError exists then delete file DistillerError
repeat until file PSName exists
delay 5
end repeat
end tell
tell application "Adobe InDesign CS2"
close thisDocument saving yes
end tell
--Opens the .ps file in Distiller, creating the PDF with the current Distiller settings.
tell application "Acrobat Distiller 7.0"
activate
open PSName
end tell
--Waits for the PDF or .log file to exist, then deletes the .ps file.
tell application "Finder"
repeat until (file PDFName exists) or (file DistillerError exists)
delay 5
end repeat
delete file PSName
end tell
--Opens the successfully created PDF in Acrobat, or informs the users of a Distiller error.
if PDFName exists then
set myPDF to PDFName as alias
tell application "Adobe Acrobat 7.0 Pro#D8C5B"
activate
open myPDF
end tell
else if DistillerError exists then
display dialog "The PostScript file failed to generate a PDF"
end if
--Deletes any unnecessary InDesign lock files and the original document, if they exist.
tell application "Finder"
try
set DoomedFile to SupportFolder&DoomedFile
delete file DoomedFile
set LockKillerItems to count of items in folder SupportFolder
repeat with i from 1 to LockKillerItems
set CurrentSuspect to item i in folder SupportFolder
if name of CurrentSuspect contains ".idlk" then
set OffWithHisHead to CurrentSuspect
end if
end repeat
delete OffWithHisHead
end try
end tell
--Function to replace string items. Variables are (String to be Changed, What will Be Replaced, What Will Replace It)
on myReplace(myString, myFindString, myChangeString)
set AppleScript's text item delimiters to myFindString
set myTextList to every text item of (myString as text)
set AppleScript's text item delimiters to myChangeString
set myString to myTextList as string
set AppleScript's text item delimiters to ""
return myString
end myReplace