8 Replies Latest reply on Jul 7, 2010 10:40 AM by Muppet Mark-QAl63s

    Trying to use Applescript to save for web

    Roger Sawhill Level 1

      I am fairly new to Applescript and have been getting frustrated trying to build a script that:

       

      1) converts a PDF to pixels

      2) flattens the image

      3) saves the image via Save for Web (JPEG, quality 60)

      4) saves the file to the Desktop using the original file name

       

      I have managed the first two, but am totally stumped on the last two. Currently my script is:

       

       

      set XXres to 85

       

      tell application "Adobe Photoshop CS4"
          set XXfile to choose file with prompt "Open file to be edited"
          open XXfile as PDF with options {class:PDF open options, mode:RGB, resolution:XXres, use antialias:true, page:1, constrain proportions:true}
          delay 1
          flatten current document
      end tell

       


      All my attempts and online searches for samples have produced negative results, any help would be greatly appreciated.

       

      Many thanks

      Roger

        • 1. Re: Trying to use Applescript to save for web
          Muppet Mark-QAl63s Level 4

          I have the Trial version of CS5 and don't have the time to fix it's AppleScript Issues (Im mostly trying to learn JavaScript instead) So this is NOT tested but I would expect you syntax to go like this…

           

          set XXres to 85
          --
          tell application "Adobe Photoshop CS5"
               set XXfile to choose file with prompt "Open file to be edited"
               open XXfile as PDF with options ¬
                    {class:PDF open options, mode:RGB, resolution:XXres, use antialias:true, page:1, constrain proportions:true}
               delay 1
               tell current document
                    set Doc_Name to name
                    flatten
                    set SFW_Options to {web format:JPEG, quality:60, with profile:false}
                    set SFW_Path to (path to desktop as text) & Doc_Name
                    export in file SFW_Path as save for web with options SFW_Options
                    close without saving
               end tell
          end tell
          
          

          • 2. Re: Trying to use Applescript to save for web
            Paul Riggott Level 6

            As you know Mark I nothing of AppleScript but I don't think your code will work without a slight amendment. When opening a PDF you can not get the path of the active document it isn't there, you must get all the details when opening the document and use that.

            • 3. Re: Trying to use Applescript to save for web
              Muppet Mark-QAl63s Level 4

              I NO need the 'path' just the name of the active document when opened will do as its saving back to the desktop's path… It may require a file extension addding to 'SFW_Path' as I can't remember off hand if the app will auto sort this with SFW? If NOT then this should do…

               

              set SFW_Path to (path to desktop as text) & Doc_Name & ".jpg"
              
              
              

               

              The document name by default is the PDF file name without extension, plus 'hyphen' and which ever page number was in the open options…

              • 4. Re: Trying to use Applescript to save for web
                Paul Riggott Level 6

                Very true Mark, I am going senile in my old age! Well that's my excuse.

                • 5. Re: Trying to use Applescript to save for web
                  Roger Sawhill Level 1

                  Mark & Paul

                   

                  Many thanks for your help, it worked like a charm - however, now I have another issue. I have expanded the script to create 3 text layers (we are creating a digital proof and neet to watermark them). The whole process works great, but, when I save the script as an application, the text layers don;t show up. I can see the layers being created in teh layers palette, but they don't show on the page --- yet if I run the exact same script from Script Editor it runs fine!? Any thoughts?

                   

                  Many thanks

                  Roger

                   

                   

                  tell application "Adobe Photoshop CS4"
                      activate
                      set MyFile to choose file with prompt "Open file to be edited"
                      open MyFile as PDF with options ¬
                          {class:PDF open options, mode:RGB, resolution:85, use antialias:true, page:1, constrain proportions:true}
                      delay 2
                      tell current document
                          --set 1st watermark
                          set textLayer to make new art layer with properties {kind:text layer, opacity:15, blend mode:multiply}
                          set contents of text object of textLayer to "PROOF"
                          set position of text object of textLayer to {765 as pixels, 575 as pixels}
                          set font of text object of textLayer to "MyriadPro-Black"
                          set size of text object of textLayer to 350
                          set justification of text object of textLayer to center
                          set stroke color of text object of textLayer to ¬
                              {class:RGB color, red:0, green:0, blue:0}
                          rotate current layer angle -20
                          --set 2nd watermark
                          set textLayer to make new art layer with properties {kind:text layer, opacity:15, blend mode:multiply}
                          set contents of text object of textLayer to "PROOF"
                          set position of text object of textLayer to {765 as pixels, 1175 as pixels}
                          set font of text object of textLayer to "MyriadPro-Black"
                          set size of text object of textLayer to 350
                          set justification of text object of textLayer to center
                          set stroke color of text object of textLayer to ¬
                              {class:RGB color, red:0, green:0, blue:0}
                          rotate current layer angle -20
                          --set 3rd watermark
                          set textLayer to make new art layer with properties {kind:text layer, opacity:15, blend mode:multiply}
                          set contents of text object of textLayer to "PROOF"
                          set position of text object of textLayer to {765 as pixels, 1750 as pixels}
                          set font of text object of textLayer to "MyriadPro-Black"
                          set size of text object of textLayer to 350
                          set justification of text object of textLayer to center
                          set stroke color of text object of textLayer to ¬
                              {class:RGB color, red:0, green:0, blue:0}
                          rotate current layer angle -20
                          --Flatten image
                          flatten
                          --Prepare for SaveForWeb
                          set Doc_Name to name
                          set SFW_Options to {web format:JPEG, quality:60, with profile:false}
                          set SFW_Path to "FreeRadical:Users:roger:Desktop:" & Doc_Name & ".jpg"
                          export in file SFW_Path as save for web with options SFW_Options
                          close without saving
                      end tell
                  end tell

                  • 6. Re: Trying to use Applescript to save for web
                    Muppet Mark-QAl63s Level 4

                    Roger, your script works just fine for me… either ran from SE or saved as app? Im only CS2 so I just comment out the SFW and close with saving to test… The words 'PROOF' are visible in both?

                    • 7. Re: Trying to use Applescript to save for web
                      Roger Sawhill Level 1

                      Yes it is odd, I tried it on my desktop machine and it wrks fine from both, but on my laptop the app does not work properly. I restarted, cross checked all software versions and system versions. Guess I'll check it on the customers mac to see if it behaves there. If so, I'll not worry about it for now, but it is odd.

                       

                      thanks

                      • 8. Re: Trying to use Applescript to save for web
                        Muppet Mark-QAl63s Level 4

                        Then I suspect your 'Hardcoded' path in your SFW part of the script. If you intend to use your script as an application that is portable then you would be better off using the standard additions 'path to' and use…

                         

                        set Foo to (path to desktop as text) & "Rest Of String"
                        

                         

                        This will get you the path from the drive name (which is variable) thru current user (which is variable) as a string…