7 Replies Latest reply on Sep 11, 2014 4:58 AM by Silly-V

    Is it possible for me to script Illustrator to save as PDF and attach to email ?

    Chezzy

      Hi,

       

      I am after a script to save my current working file as PDF (with some settings) and then bring up a blank outlook email with that file attached ?

       

      I do a lot of artwork and have to get it approved, I am getting bored of manually saving to PDF then going to find the file and then clicking send to > mail recipient etc etc

       

      You know the drill guys.

       

      So would it be possible for me to just run a script that does all that for me ready to insert the persons name or even add the persons name within the script ?

       

      thanks

       

      Lee

        • 1. Re: Is it possible for me to script Illustrator to save as PDF and attach to email ?
          Silly-V Adobe Community Professional

          Oh yea, anything is possible!  -- but it will probably be above the scope of just Illustrator scripting, this kind of script may need a VBA script for Outlook, a JSX script for Illustrator, and an Autohotkey to run them all!

          • 2. Re: Is it possible for me to script Illustrator to save as PDF and attach to email ?
            Chezzy Level 1

            I tried with js and failed, I thought it may have been fairly simple to do but i can't do it.

             

            Hay hoo

            • 3. Re: Is it possible for me to script Illustrator to save as PDF and attach to email ?
              Silly-V Adobe Community Professional

              Actually, it's probably possible with Autohotkey and Extendscript:  you rig an AHK to first run your jsx which saves a pdf and also maybe stores the name/filepath of it in a text file somewhere.  Then you have you ahk script wait a while to see if your text file is updated and the PDF has finished saving- at which point it can trigger Outlook to run with pre-filled items and attachment of the pdf file you've just saved.


              Here is the ahk email google link I've googled up: Outlook email, attachments, signatures (COM, HTML) - Scripts - AutoHotkey Community

              I kinda wanna try doing this at my work too.

              • 4. Re: Is it possible for me to script Illustrator to save as PDF and attach to email ?
                Chezzy Level 1

                That seems extremely long winded though...

                 

                Why can't they take a leaf out of Microsoft book. you can send to email from word and excel...

                 

                That would be ideal..

                • 5. Re: Re: Is it possible for me to script Illustrator to save as PDF and attach to email ?
                  Silly-V Adobe Community Professional

                  Well, as the kids' paper-crafts book I used to try to put together which frustrated the hell out of me, mockingly read on the bottom of the instructions: "ТЕРПЕНИЕ И ТРУД ВСЕ ПЕРЕТРУТ"

                  That is, patience and perseverance will overcome all. 

                  To use the below, you've gotta get Autohotkey_L, I believe, and it's not that hard to use.. but it takes some time to learn the various things if you want to write your own ones like this:

                   

                  {{YOUR_OWN_HOTKEY_HERE}}::

                    MyTempFile = C:\Users\{{YOUR_USER_NAME}}\last_proof_sent.txt

                    Run {{YOUR_JSX_SCRIPT}}.jsx                                                  ;Save the PDF proof - the script needs to write a temp text file in a place somewhere, which writes the full name of your saved PDF!

                                                                                                                            ; I called my temp text file "last_proof_sent.txt"

                    CurrentDateTime := A_Now                                                        ;get current time

                    sleep, 500

                   

                    FileGetTime, FileTime, %MyTempFile%                                              ;get mod date of this temp file

                   

                   

                    TimeCounter = 0                                                                                ;initialize time counter for waiting for PDF to save

                   

                   

                    While(CurrentDateTime > FileTime and TimeCounter < 1000)                    ;waiting period to see if temp text file has updated since start of this script

                    {

                    sleep, 20

                    TimeCounter++

                    FileGetTime, FileTime, %MyTempFile%                                                      ; each time get the modification date of the temp text file

                    }

                    If(CurrentDateTime < FileTime){

                    FileRead, MyPDFFileName, %MyTempFile%                                                  ;read the contents of temp file for location of PDF file path (It was written there by your JSX script, hopefully)

                    If Not ErrorLevel{

                    m := ComObjActive("Outlook.Application").CreateItem(0)

                    m.Subject := "Greetings to all"                                                                      ; <---- Subject -----

                    m.To := "address here"                                                                                    ; <---- Recipient -----

                    m.HTMLBody := "email body"                                                                          ; <---- Email message body -----

                    m.Display

                    m.attachments.add(MyPDFFileName)                                                             ;  This is the attachments!

                    } else {

                    MsgBox, Error Reading the temporary file %MyTempFile%

                    }

                    } else {

                    MsgBox, "Sorry, action timed-out."

                    }

                  return

                   

                  *** I have tested this on one file where I had a test folder on my desktop.  The ExtendScript likes to put the file path like "~Desktop/", but I used myFile.fsName to get the full "C:/Users/Me..." name in case it was gonna be confusing to AHK.

                  • 6. Re: Is it possible for me to script Illustrator to save as PDF and attach to email ?
                    Chezzy Level 1

                    That's great, although I don't have a jsx script that saves to PDF lol

                    • 7. Re: Is it possible for me to script Illustrator to save as PDF and attach to email ?
                      Silly-V Adobe Community Professional

                      Sorry, I thought you may have had something.  To make a script which saves a PDF is fairly straightforward: you need to take your current document and save it as PDF by changing the PDFSaveOptions and doing a document.saveAs(dest_file_obj, save_options).

                       

                      To create a text file with that PDF's name inside it, you have to create a quick file using these commands:

                      var myTxtFile = new File({{your_file_path}});

                      myTxtFile.open('w');

                      myTxtFile.write({{name_of_your_pdf_file.txt}});

                      myTxtFile.close();

                       

                      If your filepath for the myTxtFile was a valid one, you will be able to find a brand-new text file in the location you've specified it in.  It was sure a treat when I made my first one like that!  Anyways, this same file will be overwritten everytime you save the PDF in this manner.  The name of the pdf will be written inside it, and that's how the Autohotkey will know what file to attch to your email.  The modified timestamp on that file will also let Autohotkey know that the PDF has been saved fully so it doesn't try to attach it too soon.  If the PDF takes longer than the timing loop within the AHK script, it will produce you a timeout message.

                       

                      In case you're new to Extendscript, to get started trying to figure out your PDF saving script, use this as a starting point:

                       

                      #target illustrator

                       

                      function myScript(){

                           if(app.documents.length>0){

                                var doc=app.activeDocument;

                                alert("Name of my current document is: "+doc.name);

                           } else {

                                alert("gotta have a document open to save as PDF!");

                           }

                      }

                       

                      myScript();

                       

                      Press F1 to open the Object Model Viewer to see all the commands you can do with the 'doc' variable.. including the saveAs.