Author Topic: Exporting PDFs and attaching to an email  (Read 511 times)

0 Members and 1 Guest are viewing this topic.

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Exporting PDFs and attaching to an email
« on: April 20, 2016, 03:48:18 PM »
I have a script that exports a pdf in InDesign and attaches that pdf to a new email. Right now, if I drop 3 files on the script, it creates 3 separate emails with one attachment each. What I want it to do is create ONE email with three attachments. I know I need to take the part that creates the email in outlook out of the repeat loop. I'm not sure how to loop through the exported pdfs to get them to attach to the email, one by one. Is there a way to add the pdf files to some sort of list? Any help is appreciated :)

on open droppedfiles
   
   
   
Code: [Select]
	---------------------------------------------------------------------

--PART #1 - GETTING THE FILE NAME AND PATH AND CREATING PDF FILE

tell application "Adobe InDesign CC 2014" to activate
repeat with afile in droppedfiles

--GETTING RID OF INTERRUPTING MISSING FONT & IMAGE DIALOG BOXES
tell application "Adobe InDesign CC 2014"
set user interaction level of script preferences to never interact
tell PDF export preferences
set view PDF to false
end tell

--OPENING THE FILE IN INDESIGN
open afile

--DECLARING VARIABLE FOR MISSING LINKS/IMAGES AND THE PATH TO THE DOCUMENT
set my_destination to (path to desktop) as string
set doc_name to get name of active document as string
set pdf_name to text 1 thru -6 of doc_name as string
set pdf_destination to my_destination & pdf_name & "_LoRes" & ".pdf"

--TELLING IN DESIGN TO CREATE PDF FILE IF NO FONTS/IMAGES ARE MISSING
tell document 1


--EXPORTING THE PDF
export format PDF type to pdf_destination using "IDPDF_LoRes" without showing options
close afile saving no


--RESETTING USER INTERACTION SO DIALOG BOXES COME UP AGAIN
tell application "Adobe InDesign CC 2014"
set user interaction level of script preferences to interact with all

end tell

end tell
end tell


---------------------------------------------------------------

--PART #2 - CREATING A NEW EMAIL MESSAGE WITH THE FILE ATTACHED


tell application "Microsoft Outlook"
set pdfFile to pdf_destination as alias
set newMessage to make new outgoing message with properties {subject:"Proof of " & pdf_name & " sign", content:"Attached is a proof of the " & pdf_name & " sign" & "." & " Please let me know if there are any revisions or if it is good to print as is." & "<br>" & ":-)" & "<br>" & "<br>" & "Thanks!"}
tell newMessage
repeat
make new attachment with properties {file:pdfFile}
end repeat
end tell
open newMessage
end tell


---------------------------------------------------------------

end repeat
---------------------------------------------------------------------







end open



Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: Exporting PDFs and attaching to an email
« Reply #1 on: April 21, 2016, 02:38:56 AM »
Hi! I don't use InDesign as far as I'm concerned, but never mind, it has nothing to do here. To put the thing simple, you need to attach 3 files to a new email. So what you'll need to do is or to stock the 3 aliases in a list and then pick up the files one by one (which is actually top fast when running) to attach them; or to insert the PDF generation inside of the repeat loop in the Outlook block.
For instance:
Code: [Select]
on open droppedfiles

tell application "Adobe InDesign CC 2014" to activate

--PART 1
--THE MAIN PART SHALL CREATE THE NEW OUTGOING MESSAGE
tell application "Microsoft Outlook"
        set newMessage to make new outgoing message with properties {subject:"Proof of " & pdf_name & " sign", content:"Attached is a proof of the " & pdf_name & " sign" & "." & " Please let me know if there are any revisions or if it is good to print as is." & "<br>" & ":-)" & "<br>" & "<br>" & "Thanks!"}
        tell newMessage

--PROCESSING THE DROPPED FILES WOULD TAKE PLACE HERE           
        repeat with afile in droppedfiles
                set pdfFile to my ProcessFile(afile) --CALLING HANDLER PROCESSFILE FOR EACH DROPPED FILE
                make new attachment with properties {file:pdfFile} --ATTACHING EACH GENERATED PDF
            end repeat
        end tell
        open newMessage
end tell

--RESETTING USER INTERACTION SO DIALOG BOXES COME UP AGAIN
tell application "Adobe InDesign CC 2014"
     set user interaction level of script preferences to interact with all
                   
end tell
 

--PART 2       
--HANDLER PROCESSFILE
on ProcessFile(the_file)
        --GETTING RID OF INTERRUPTING MISSING FONT & IMAGE DIALOG BOXES
        tell application "Adobe InDesign CC 2014"
            set user interaction level of script preferences to never interact
            tell PDF export preferences
                set view PDF to false
            end tell
           
            --OPENING THE FILE IN INDESIGN
            open the_file
           
            --DECLARING VARIABLE FOR MISSING LINKS/IMAGES AND THE PATH TO THE DOCUMENT
            set my_destination to (path to desktop) as string
            set doc_name to get name of active document as string
            set pdf_name to text 1 thru -6 of doc_name as string
            set pdf_destination to my_destination & pdf_name & "_LoRes" & ".pdf"
           
            --TELLING IN DESIGN TO CREATE PDF FILE IF NO FONTS/IMAGES ARE MISSING
            tell document 1
               
               
                --EXPORTING THE PDF
                export format PDF type to pdf_destination using "IDPDF_LoRes" without showing options
                close afile saving no
               
                             
            end tell
        end tell
       set the_pdf_file to pdf_destination as alias
       return the_pdf_file       

end ProcessFile

Does it make sense? Does it work as expected?
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: Exporting PDFs and attaching to an email
« Reply #2 on: April 21, 2016, 03:32:34 PM »
Thanks Jean-Marie! It is working. I'm playing with using if statements to change the subject name and content of the email based on how many files are dropped on the script. It looks like it's working nicely. I'll post the final code when I'm done with that part. :)

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: Exporting PDFs and attaching to an email
« Reply #3 on: April 21, 2016, 03:56:04 PM »
Here's the final code of my pdf and email script. :) So how did you learn applescript Jean-Marie? I've been using google to learn in between other work for the past year, but I'm sure there's a lot I haven't learned yet.

Code: [Select]
global my_pdf_choice

on open droppedfiles

-------------------------------------------------

--PART 1
--PROMPTING THE USER FOR WHICH PDF PRESET THEY WANT
tell application "Adobe InDesign CC 2014"
set my_pdf_export to get the name of every PDF export preset
set my_pdf_choice to (choose from list my_pdf_export) as string
end tell


-------------------------------------------------

--PART 2
--GETTING EMAIL SUBJECT AND CONTENT INFORMATION

tell application "Finder"
if (count of droppedfiles) is greater than 1 as integer then --IF MORE THAN ONE FILE IS DROPPED, THE SUBJECT AND CONTENT IS SET IN THE 2 LINES BELOW
set subjectName to "Proof of signs"
set contentInfo to "I've attached " & (count of droppedfiles) & " proofs" & "." & " Please let me know if there are any revisions or if the signs are good to print as is." & "<br>" & ":-)" & "<br>" & "<br>" & "Thanks!"
else --IF JUST ONE FILE IS DROPPED THE SUBJECT & CONTENT DEFAULTS TO BELOW LINES
repeat with the_file in droppedfiles
if name of the_file does not contain "sign" as string then
set fullName to name of the_file as string
set shortName to text 1 thru -6 of fullName
set subjectName to "Proof of " & shortName & " sign"
set contentInfo to "Attached is a proof of " & shortName & " sign" & "." & " Please let me know if there are any revisions or if it is good to print as is." & "<br>" & ":-)" & "<br>" & "<br>" & "Thanks!"
else
set subjectName to "Proof of " & fullName
set contentInfo to "Attached is a proof of " & shortName & "." & " Please let me know if there are any revisions or if it is good to print as is." & "<br>" & ":-)" & "<br>" & "<br>" & "Thanks!"
end if
end repeat
end if
end tell

-------------------------------------------------

--ACTIVATING INDESIGN
tell application "Adobe InDesign CC 2014" to activate

-------------------------------------------------


--PART 3
--THE MAIN PART SHALL CREATE THE NEW OUTGOING MESSAGE
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:subjectName, content:contentInfo}
tell newMessage

--PROCESSING THE DROPPED FILES WOULD TAKE PLACE HERE           
repeat with the_file in droppedfiles
set pdfFile to my ProcessFile(the_file) --CALLING HANDLER PROCESSFILE FOR EACH DROPPED FILE
make new attachment with properties {file:pdfFile} --ATTACHING EACH GENERATED PDF
end repeat
end tell
open newMessage
end tell


--RESETTING USER INTERACTION SO DIALOG BOXES COME UP AGAIN
tell application "Adobe InDesign CC 2014"
set user interaction level of script preferences to interact with all

end tell

end open

-------------------------------------------------


--PART 4       
--HANDLER PROCESSFILE
on ProcessFile(the_file)

--GETTING RID OF INTERRUPTING MISSING FONT & IMAGE DIALOG BOXES
tell application "Adobe InDesign CC 2014"
set user interaction level of script preferences to never interact
tell PDF export preferences
set view PDF to false
end tell

--OPENING THE FILE IN INDESIGN
open the_file

--DECLARING VARIABLE FOR MISSING LINKS/IMAGES AND THE PATH TO THE DOCUMENT
set my_destination to (path to desktop) as string
set doc_name to get name of active document as string
set pdf_name to text 1 thru -6 of doc_name as string
set pdf_destination to my_destination & pdf_name & ".pdf"

--TELLING IN DESIGN TO CREATE PDF FILE IF NO FONTS/IMAGES ARE MISSING
tell document 1

--EXPORTING THE PDF
export format PDF type to pdf_destination using my_pdf_choice without showing options
close the_file saving no

end tell
end tell
set the_pdf_file to pdf_destination as alias
return the_pdf_file

end ProcessFile

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: Exporting PDFs and attaching to an email
« Reply #4 on: April 26, 2016, 02:46:26 AM »
To be honest, I've started with lasy bones questions: how to have the Mac doing all my repetitive tasks and how to improve Quark? And I ended with the same question as yours. I asked Michel, aka Scripting_Ace on Quark forums. He helped me very kindly with specific requests from me. Then I learnt a lot on the Web. Then I failed (and still fail) on so many points and that's probably the best school :-) But Michel was definately my best teacher, simple and clever. He pointed many details like that and corrected me so many times! But, again, I still come accross issues, stupid errors, and so on. That's why lists and forums are the best place to get help.
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =