6 Replies Latest reply on Mar 19, 2013 3:49 PM by Muppet Mark

    HOW? = export to same folder without errors

    scott memberg

      Hey Guys,

       

      Ok here is my issue. I have to do several things to a document in indesign when I am finished. I have to save it as a PDF, make JPGs of the page/s and save it and close it. I have been spending HOURS trying to figure out this scripting thing. Here is what i have so far:

       

      tell application "Adobe InDesign CS5.5"

                set properties of PDF export preferences to properties of PDF export preset "[High Quality Print]"

                set theFilepath to file path of active document

                tell active document

        export format PDF type to theFilepath without showing options

                end tell

      --JPEG Preference Settings

                set myJPEG_Prefs to JPEG export preferences

                tell myJPEG_Prefs

                          set resolution to 48

                          set JPEG Quality to maximum

                          set JPEG export range to export range

                          set JPEG Rendering style to baseline encoding

                end tell

      --save file

                if modified of active document is true then

                          tell active document to save

                end if

      close active document

      end tell

       

       

      Problem is that I get an error when i run it:

       

      Result:

      error "Adobe InDesign CS5.5 got an error: Cannot save to the file “Desktop”, because it is already open." number 9491

       

      In the "events window":

      tell application "Adobe InDesign CS5.5"

      set properties of PDF export preferences to properties of PDF export preset "[High Quality Print]"

      get file path of active document

        --> file "Web Design 1:Users:scottmemberg:Desktop:"

      export active document format PDF type to file "Web Design 1:Users:scottmemberg:Desktop:" without showing options

        --> error "Cannot save to the file “Desktop”, because it is already open." number 9491

       

       

      Where did I go wrong? Do i need an "if" statement some where? Please Help!


        • 1. Re: HOW? = export to same folder without errors
          Muppet Mark Level 5

          The line…

           

          set theFilepath to file path of active document

           

          Is not correct… This returns the files parent ie ( the desktop folder ) you can't export to this… try something like…

           

          set theFilepath to file path of active document & "myFile.pdf"

           

          of cause I did no check this file already exist so it would be overwritten… if it did…

          • 2. Re: HOW? = export to same folder without errors
            Jump_Over Level 5

            Hi,

             

            theFilepath is the last folder from your file path but supposed to be a file.

            so use it like this:

            tell application "Adobe InDesign CS5.5"

                      set properties of PDF export preferences to properties of PDF export preset "[High Quality Print]"

                      set myDestination to file path of active document as string

                      set myDocname to get name of active document

                      if myDocname contains "indd" then set myDocname to (characters 1 thru -6 of myDocname)

              tell active document

                   export format PDF type to myDestination & myDocname & ".pdf" without showing options

              end tell

             

            In case of .jpg is the same story

             

            Jarek

             

            (oh, sorry Mark, didn't see yours, coffee, cigarettes and time is running )

             

            Message was edited by: Jump_Over

            • 3. Re: HOW? = export to same folder without errors
              scott memberg Level 1

              I have re-worked some of the script:

               

              tell application "Adobe InDesign CS5.5"

                        set properties of PDF export preferences to properties of PDF export preset "[High Quality Print]"

                        set myJPEG_Prefs to JPEG export preferences

                        tell myJPEG_Prefs

                                  set resolution to 48

                                  set JPEG Quality to maximum

                                  set JPEG export range to export range

                                  set JPEG Rendering style to baseline encoding

                        end tell

                        set myDestination to file path of active document as string

                        set myDocname to get name of active document

                        if myDocname contains "indd" then set myDocname to (characters 1 thru -6 of myDocname)

                        tell active document

                export format PDF type to myDestination & myDocname & ".pdf" without showing options

                        end tell

                        tell active document

                export format JPEG to myDestination & myDocname & ".jpeg" without showing options

                        end tell

              end tell

               

               

              BUT, it has a problem with the jpeg part.... im so close.

              • 4. Re: HOW? = export to same folder without errors
                Muppet Mark Level 5

                It's the same problem as before… You need to export a file to the full file path of a file not a folder… Choose folder will return a folder… add name & file extension to this and you will have a valid full path in which to save…

                 

                'Web Design 1:Users:scottmemberg:Desktop:' -- this is just partial path

                 

                'Web Design 1:Users:scottmemberg:Desktop:foo.pdf' -- this would be a full path ( it no end in : a folder in HFS path )

                • 5. Re: HOW? = export to same folder without errors
                  scott memberg Level 1

                  Thanks guys for your help! Here is what I arrived at and it works perfectly for me.

                   

                  tell application "Adobe InDesign CS5.5"

                            set properties of PDF export preferences to properties of PDF export preset "crops-bleeds"

                            set myJPEG_Prefs to JPEG export preferences

                            tell myJPEG_Prefs

                                      set resolution to 48

                                      set JPEG Quality to maximum

                                      set JPEG export range to export all

                                      set JPEG Rendering style to baseline encoding

                            end tell

                            set myDestination to file path of active document as string

                            set myDocname to get name of active document

                            if myDocname contains "indd" then set myDocname to (characters 1 thru -6 of myDocname)

                            tell active document

                    export format PDF type to myDestination & myDocname & ".pdf" without showing options

                            end tell

                            tell active document

                    export format JPG to myDestination & myDocname & ".jpg" without showing options

                            end tell

                            if modified of active document is true then

                                      tell active document to save

                    close active document

                            end if

                            if modified of active document is false then

                    close active document

                            end if

                  end tell

                   

                   

                  And now with 1 button i can save my finger in clicking time...rofl

                  • 6. Re: HOW? = export to same folder without errors
                    Muppet Mark Level 5

                    Untested but you don't need to step in & out of tall blocks like that…

                     

                    tell application "Adobe InDesign CS5"

                              set properties of PDF export preferences to properties of PDF export preset "crops-bleeds"

                              set myJPEG_Prefs to JPEG export preferences

                              tell myJPEG_Prefs

                                        set resolution to 48

                                        set JPEG Quality to maximum

                                        set JPEG export range to export all

                                        set JPEG Rendering style to baseline encoding

                              end tell

                              tell active document

                                        set myDestination to file path as string

                                        set myDocname to get name

                                        if myDocname contains "indd" then set myDocname to (characters 1 thru -6 of myDocname)

                      export format PDF type to myDestination & myDocname & ".pdf" without showing options

                      export format JPG to myDestination & myDocname & ".jpg" without showing options

                                        if modified is true then save

                      close active document

                              end tell

                    end tell