Hello everyone,
I am new to AppleScript and I have a project I have been working on off and on now for a few weeks. It is cobbled together from things I have seen here and through some Google-fu.
I work at a printing company and we send out PDF proofs. We want to automate that process. What I have works and works well, but I am sure it can be cleaned up to be more efficient and possibly quicker (though I don’t find it to be slow).
What it does is when I export a PDF it gets the Metadata for the Group Name and stores it as a variable, then it strips the file name down to just the job/quote number. It then watermarks, each file and saves to the groups folder. Then finds all items for that same job number and combines them into one as saves to a different folder where it will get a sign off sheet and security applied.
Hopefully it is fairly clear how I am doing all of this when you see the code…it’s a lot! Well to me anyway. There are a bunch of situations that could be in play so there are a ton of if statements. I just finished adding a bunch to cover a situation where there might be some items that are under a job number and others start as a quote but get exported at the same time. We are using a script in InDesign that will export a PDF of all open windows at once.
Thanks for your time!
-- strip _ or - from filename
on findAndReplaceInText(theText, theSearchString, theReplacementString)
set AppleScript's text item delimiters to theSearchString
set theTextItems to every text item of theText
set AppleScript's text item delimiters to theReplacementString
set theText to theTextItems as string
set AppleScript's text item delimiters to ""
return theText
end findAndReplaceInText
-- split filename into pieces
on splitText(theText, theDelimiter)
set AppleScript's text item delimiters to theDelimiter
set theTextItems to every text item of theText
set AppleScript's text item delimiters to ""
return theTextItems
end splitText
--folders to empty after script is finished
set deleteWM to ":Users:Prepress:Desktop:Proofing:ToWatermark"
set deleteWMNSO to ":Users:Prepress:Desktop:Proofing:ToWatermark_NSO"
set deleteASF to ":Users:Prepress:Desktop:Proofing:AddSignOff"
-- find group name
tell application "Finder" to set pdfList to (files of folder "ToWatermark" of folder "Proofing" of desktop) as alias list
tell application "Finder" to set metadataFile to (item 1 of my pdfList) as alias
set groupName to do shell script "mdls -name kMDItemTitle -raw " & space & quoted form of POSIX path of metadataFile
-- find job numbers
set filesFound to {}
set jobNumbers to {}
set job1Files to {}
set job2Files to {}
set nextItem to 1
tell application "Finder" to set myFiles to name of every file of (folder "ToWatermark" of folder "Proofing" of desktop)
--loop used for populating list filesFound with all filenames found
repeat with i in myFiles
set end of filesFound to (item nextItem of myFiles)
set nextItem to (nextItem + 1)
end repeat
set nextItem to 1 --reset counter to 1
--loop used for pulling each filename from list filesFound and return all job numbers
repeat with i in filesFound
if text 6 through 7 of i contains "_" then
set end of jobNumbers to item 1 of (splitText(item nextItem of filesFound, "_"))
set nextItem to (nextItem + 1)
else if text 6 through 7 of i contains "-" then
set end of jobNumbers to item 1 of (splitText(item nextItem of filesFound, "-"))
set nextItem to (nextItem + 1)
else
set end of jobNumbers to item 1 of (splitText(item nextItem of filesFound, space))
set nextItem to (nextItem + 1)
end if
end repeat
--remove duplicate listings
set jobList to items of jobNumbers
set uniquelist to {}
repeat with i from 1 to count of jobList
set thisJob to item i of jobList
if thisJob is not in uniquelist then set end of uniquelist to thisJob
end repeat
--set variables for unique job numbers found
try
set jobNumber1 to item 1 of uniquelist
set jobNumber2 to item 2 of uniquelist
end try
-- find how many items each job number has
on count_matches(this_list, this_item)
set the match_counter to 0
repeat with i from 1 to the count of this_list
if item i of this_list is this_item then ¬
set the match_counter to the match_counter + 1
end repeat
return the match_counter
end count_matches
try
set job1Items to count_matches(jobList, jobNumber1)
set job2Items to count_matches(jobList, jobNumber2)
end try
-- settings to be used or combining PDFs later
set outputFolder to "/Users/Prepress/Desktop/Proofing/AddSignOff/"
set pdfFiles to ""
-- find other items in job
if (count of uniquelist) is 1 then --only 1 job number
set matchingPDFs to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber1 & "*.pdf\"" --search for pdfs with same job number in Printers Plan PDF folder for current group
set outputFile to (outputFolder as text) & jobNumber1 & ".pdf" --combining variable
else if (count of uniquelist) is 2 then --2 job numbers
set matchingPDFs1 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber1 & "*.pdf\"" --search for pdfs with first job number in Printers Plan PDF folder for current group
set matchingPDFs2 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber2 & "*.pdf\"" --search for pdfs with second job number in Printers Plan PDF folder for current group
set outputFile1 to (outputFolder as text) & jobNumber1 & ".pdf" --combining variable
set outputFile2 to (outputFolder as text) & jobNumber2 & ".pdf" --combining variable
end if
-- Acrobat scripts
set WaterMark to "this.addWatermarkFromFile({
cDIPath: '/Volumes/bipserver/BIP Library Stuff/proof stamp.pdf',
nHorizAlign: app.constants.align.center,
nVertAlign: app.constants.align.center,
nRotation: 45,
nScale: -1,
bOnScreen: false
});"
set destFolder to "/Volumes/bipserver/PrintersPlan_PDF_Files/ /"
set destFolder to findAndReplaceInText(destFolder, " ", groupName) as string
set destFolder2 to ("this.saveAs(" & (destFolder as string) & " + this.documentFileName);")
set destFolder2 to findAndReplaceInText(destFolder2, "(/", "('/") as string
set destFolder2 to findAndReplaceInText(destFolder2, "/ +", "/' +") as string
set SaveGroupFolder to destFolder2 as string
set SignOffSheet to "this.insertPages ({
nPage: -1,
cPath: '/Volumes/bipserver/BIP Library Stuff/PDF Proof box 1-16.pdf',
nStart: 0
});"
set PDF_Security to "var policyArray = security.getSecurityPolicies(); for (var i = 0; i < policyArray.length; i++) {if (policyArray[i].name == 'BIPPDF') { var myPolicy = policyArray[i]}} this.encryptUsingPolicy( myPolicy );"
set SaveAs to "this.saveAs('/Volumes/bipserver/PDFs_for_Email/' + this.documentFileName);"
try
set SaveAsJobNumber1 to "this.saveAs('/Volumes/bipserver/PDFs_for_Email/' + this.documentFileName);"
set SaveAsJobNumber1 to findAndReplaceInText(SaveAsJobNumber1, "this.documentFileName", quoted form of jobNumber1) as string
set SaveAsJobNumber1 to findAndReplaceInText(SaveAsJobNumber1, "');", ".pdf');") as string
set SaveAsJobNumber2 to "this.saveAs('/Volumes/bipserver/PDFs_for_Email/' + this.documentFileName);"
set SaveAsJobNumber2 to findAndReplaceInText(SaveAsJobNumber2, "this.documentFileName", quoted form of jobNumber2) as string
set SaveAsJobNumber2 to findAndReplaceInText(SaveAsJobNumber2, "');", ".pdf');") as string
end try
set ClosePDF to "this.closeDoc();"
-- processing
if (count of uniquelist) is 1 then -- only one job number
if (count of paragraphs in my matchingPDFs) is 0 and (count of items in my pdfList) is 1 then -- first proof, single item, do whole process in one pass
tell application "Adobe Acrobat"
open my pdfList
do script my WaterMark
do script my SaveGroupFolder
do script my SignOffSheet
do script my PDF_Security
do script my SaveAsJobNumber1
do script my ClosePDF
end tell
else if (count of paragraphs in my matchingPDFs) is 0 and (count of items in my pdfList) is greater than 1 then --first proof, multiple items, watermark all then do rest
tell application "Adobe Acrobat"
repeat with listItem in my pdfList
open listItem
do script my WaterMark
do script my SaveGroupFolder
do script my ClosePDF
end repeat
end tell
set matchingPDFs to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber1 & "*.pdf\""
tell application "Finder" to set pdfsToCombine to paragraphs of my matchingPDFs as alias list
repeat with p in my pdfsToCombine
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
else if (count of paragraphs in my matchingPDFs) is greater than 0 then --not first proof, watermark all then do rest
tell application "Adobe Acrobat"
repeat with listItem in my pdfList
open listItem
do script my WaterMark
do script my SaveGroupFolder
do script my ClosePDF
end repeat
end tell
set matchingPDFs to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber1 & "*.pdf\""
tell application "Finder" to set pdfsToCombine to paragraphs of my matchingPDFs as alias list
if (count of items in pdfsToCombine) is 1 then
tell application "Adobe Acrobat"
open my pdfsToCombine
do script my SignOffSheet
do script my PDF_Security
do script my SaveAsJobNumber1
do script my ClosePDF
end tell
else
repeat with p in my pdfsToCombine
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
end if
end if
else if (count of uniquelist) is 2 then -- two job numbers
if (count of paragraphs in my matchingPDFs1) is 0 and (count of paragraphs in my matchingPDFs2) is 0 then --no pdfs for either in PrintersPlanPDFs
if job1Items is 1 and job2Items is 1 then --one item for each number, first proof, do whole thing in one pass for each file
tell application "Adobe Acrobat"
open item 1 of my pdfList
do script my WaterMark
do script my SaveGroupFolder
do script my SignOffSheet
do script my PDF_Security
do script my SaveAsJobNumber1
do script my ClosePDF
open item 2 of my pdfList
do script my WaterMark
do script my SaveGroupFolder
do script my SignOffSheet
do script my PDF_Security
do script my SaveAsJobNumber2
do script my ClosePDF
end tell
else if job1Items is greater than 1 and job2Items is 1 then --multiple items for first number, one item for second. watermark all for first then do rest. do whole process in one pass for second job number
set nextItem to 1
try
repeat with i in my pdfList
if nextItem is less than or equal to job1Items then
set end of job1Files to (item nextItem of my pdfList)
set nextItem to (nextItem + 1)
end if
end repeat
end try
tell application "Adobe Acrobat"
open item (job1Items + 1) of my pdfList
do script my WaterMark
do script my SaveGroupFolder
do script my SignOffSheet
do script my PDF_Security
do script my SaveAsJobNumber2
do script my ClosePDF
repeat with listItem in my job1Files
open listItem
do script my WaterMark
do script my SaveGroupFolder
do script my ClosePDF
end repeat
end tell
set matchingPDFs1 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber1 & "*.pdf\""
tell application "Finder" to set pdfsToCombine1 to paragraphs of my matchingPDFs1 as alias list
repeat with p in my pdfsToCombine1
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile1 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
else if job1Items is 1 and job2Items is greater than 1 then --one item for first number, multiple for second, do whole process in one pass for first job number, watermark all in second then do rest
set nextItem to (job1Items + 1)
try
repeat with i in my pdfList
set end of job2Files to (item nextItem of my pdfList)
set nextItem to (nextItem + 1)
end repeat
end try
tell application "Adobe Acrobat"
open item 1 of my pdfList
do script my WaterMark
do script my SaveGroupFolder
do script my SignOffSheet
do script my PDF_Security
do script my SaveAsJobNumber1
do script my ClosePDF
repeat with listItem in my job2Files
open listItem
do script my WaterMark
do script my SaveGroupFolder
do script my ClosePDF
end repeat
end tell
set matchingPDFs2 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber2 & "*.pdf\""
tell application "Finder" to set pdfsToCombine2 to paragraphs of my matchingPDFs2 as alias list
repeat with p in my pdfsToCombine2
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile2 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
else if job1Items is greater than 1 and job2Items is greater than 1 then --multiple items for both numbers, watermark all items then combine jobs separately and complete
tell application "Adobe Acrobat"
repeat with listItem in my pdfList
open listItem
do script my WaterMark
do script my SaveGroupFolder
do script my ClosePDF
end repeat
end tell
set matchingPDFs1 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber1 & "*.pdf\""
set matchingPDFs2 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber2 & "*.pdf\""
tell application "Finder"
set pdfsToCombine1 to paragraphs of my matchingPDFs1 as alias list
set pdfsToCombine2 to paragraphs of my matchingPDFs2 as alias list
end tell
repeat with p in my pdfsToCombine1
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile1 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
tell application "System Events" to delete (files of folder deleteASF)
set pdfFiles to ""
repeat with p in my pdfsToCombine2
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile2 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
end if
else if (count of paragraphs in my matchingPDFs1) is greater than 0 and (count of paragraphs in my matchingPDFs2) is 0 then --pdfs for first, no pdfs for second in PrintersPlanPDFs
if job1Items is 1 and job2Items is 1 then
tell application "Adobe Acrobat"
open item 1 of my pdfList
do script my WaterMark
do script my SaveGroupFolder
do script my ClosePDF
open item 2 of my pdfList
do script my WaterMark
do script my SaveGroupFolder
do script my SignOffSheet
do script my PDF_Security
do script my SaveAsJobNumber2
do script my ClosePDF
end tell
set matchingPDFs1 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber1 & "*.pdf\""
tell application "Finder" to set pdfsToCombine1 to paragraphs of my matchingPDFs1 as alias list
repeat with p in my pdfsToCombine1
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile1 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
else if job1Items is greater than 1 and job2Items is 1 then
set nextItem to 1
try
repeat with i in my pdfList
if nextItem is less than or equal to job1Items then
set end of job1Files to (item nextItem of my pdfList)
set nextItem to (nextItem + 1)
end if
end repeat
end try
tell application "Adobe Acrobat"
open item (job1Items + 1) of my pdfList
do script my WaterMark
do script my SaveGroupFolder
do script my SignOffSheet
do script my PDF_Security
do script my SaveAsJobNumber2
do script my ClosePDF
repeat with listItem in my job1Files
open listItem
do script my WaterMark
do script my SaveGroupFolder
do script my ClosePDF
end repeat
end tell
set matchingPDFs1 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber1 & "*.pdf\""
tell application "Finder" to set pdfsToCombine1 to paragraphs of my matchingPDFs1 as alias list
repeat with p in my pdfsToCombine1
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile1 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
else if job1Items is 1 and job2Items is greater than 1 then
tell application "Adobe Acrobat"
repeat with listItem in my pdfList
open listItem
do script my WaterMark
do script my SaveGroupFolder
do script my ClosePDF
end repeat
end tell
set matchingPDFs1 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber1 & "*.pdf\""
set matchingPDFs2 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber2 & "*.pdf\""
tell application "Finder"
set pdfsToCombine1 to paragraphs of my matchingPDFs1 as alias list
set pdfsToCombine2 to paragraphs of my matchingPDFs2 as alias list
end tell
repeat with p in my pdfsToCombine1
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile1 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
tell application "System Events" to delete (files of folder deleteASF)
set pdfFiles to ""
repeat with p in my pdfsToCombine2
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile2 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
else if job1Items is greater than 1 and job2Items is greater than 1 then
tell application "Adobe Acrobat"
repeat with listItem in my pdfList
open listItem
do script my WaterMark
do script my SaveGroupFolder
do script my ClosePDF
end repeat
end tell
set matchingPDFs1 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber1 & "*.pdf\""
set matchingPDFs2 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber2 & "*.pdf\""
tell application "Finder"
set pdfsToCombine1 to paragraphs of my matchingPDFs1 as alias list
set pdfsToCombine2 to paragraphs of my matchingPDFs2 as alias list
end tell
repeat with p in my pdfsToCombine1
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile1 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
tell application "System Events" to delete (files of folder deleteASF)
set pdfFiles to ""
repeat with p in my pdfsToCombine2
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile2 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
end if
else if (count of paragraphs in my matchingPDFs1) is 0 and (count of paragraphs in my matchingPDFs2) is greater than 0 then --no pdfs for first, pdfs for second in PrintersPlanPDFs
if job1Items is 1 and job2Items is 1 then
tell application "Adobe Acrobat"
open item 1 of my pdfList
do script my WaterMark
do script my SaveGroupFolder
do script my SignOffSheet
do script my PDF_Security
do script my SaveAsJobNumber1
do script my ClosePDF
open item 2 of my pdfList
do script my WaterMark
do script my SaveGroupFolder
do script my ClosePDF
end tell
set matchingPDFs2 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber2 & "*.pdf\""
tell application "Finder" to set pdfsToCombine2 to paragraphs of my matchingPDFs2 as alias list
repeat with p in my pdfsToCombine2
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile2 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
else if job1Items is greater than 1 and job2Items is 1 then
tell application "Adobe Acrobat"
repeat with listItem in my pdfList
open listItem
do script my WaterMark
do script my SaveGroupFolder
do script my ClosePDF
end repeat
end tell
set matchingPDFs1 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber1 & "*.pdf\""
set matchingPDFs2 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber2 & "*.pdf\""
tell application "Finder"
set pdfsToCombine1 to paragraphs of my matchingPDFs1 as alias list
set pdfsToCombine2 to paragraphs of my matchingPDFs2 as alias list
end tell
repeat with p in my pdfsToCombine1
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile1 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
tell application "System Events" to delete (files of folder deleteASF)
set pdfFiles to ""
repeat with p in my pdfsToCombine2
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile2 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
else if job1Items is 1 and job2Items is greater than 1 then
set nextItem to (job1Items + 1)
try
repeat with i in my pdfList
if nextItem is less than or equal to job2Items then
set end of job2Files to (item nextItem of my pdfList)
set nextItem to (nextItem + 1)
end if
end repeat
end try
tell application "Adobe Acrobat"
open item 1 of my pdfList
do script my WaterMark
do script my SaveGroupFolder
do script my SignOffSheet
do script my PDF_Security
do script my SaveAsJobNumber1
do script my ClosePDF
repeat with listItem in my job2Files
open listItem
do script my WaterMark
do script my SaveGroupFolder
do script my ClosePDF
end repeat
end tell
set matchingPDFs2 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber2 & "*.pdf\""
tell application "Finder" to set pdfsToCombine2 to paragraphs of my matchingPDFs2 as alias list
repeat with p in my pdfsToCombine2
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile2 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
else if job1Items is greater than 1 and job2Items is greater than 1 then
tell application "Adobe Acrobat"
repeat with listItem in my pdfList
open listItem
do script my WaterMark
do script my SaveGroupFolder
do script my ClosePDF
end repeat
end tell
set matchingPDFs1 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber1 & "*.pdf\""
set matchingPDFs2 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber2 & "*.pdf\""
tell application "Finder"
set pdfsToCombine1 to paragraphs of my matchingPDFs1 as alias list
set pdfsToCombine2 to paragraphs of my matchingPDFs2 as alias list
end tell
repeat with p in my pdfsToCombine1
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile1 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
tell application "System Events" to delete (files of folder deleteASF)
set pdfFiles to ""
repeat with p in my pdfsToCombine2
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile2 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
end if
else if (count of paragraphs in my matchingPDFs1) is greater than 0 and (count of paragraphs in my matchingPDFs2) is greater than 0 then --pdfs for both in PrintersPlanPDFs
tell application "Adobe Acrobat"
repeat with listItem in my pdfList
open listItem
do script my WaterMark
do script my SaveGroupFolder
do script my ClosePDF
end repeat
end tell
set matchingPDFs1 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber1 & "*.pdf\""
set matchingPDFs2 to do shell script "find \"/Volumes/bipserver/PrintersPlan_PDF_Files/" & groupName & "\" -name \"" & jobNumber2 & "*.pdf\""
tell application "Finder"
set pdfsToCombine1 to paragraphs of my matchingPDFs1 as alias list
set pdfsToCombine2 to paragraphs of my matchingPDFs2 as alias list
end tell
repeat with p in my pdfsToCombine1
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile1 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
tell application "System Events" to delete (files of folder deleteASF)
set pdfFiles to ""
repeat with p in my pdfsToCombine2
set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
end repeat
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of my outputFile2 & my pdfFiles
tell application "Finder" to set proofPDF to (files of folder "AddSignOff" of folder "Proofing" of desktop) as alias
tell application "Adobe Acrobat"
open my proofPDF
do script my SignOffSheet
do script my PDF_Security
do script my SaveAs
do script my ClosePDF
end tell
end if
end if
tell application "System Events"
delete (files of folder deleteWM)
delete (files of folder deleteASF)
delete (files of folder deleteWMNSO)
end tell