1 Reply Latest reply on Jan 26, 2017 5:32 PM by JavierAroche

    Scripting Save for Web

    MilesKelly97

      Hey guys

       

      I am trying to script for Save for Web with a simple AppleScript that will later be added asa process in a much learger script that  takes ai files exported to psd's and takes them into Photoshop to push them out as sRGB png's.

       

      My script is

      set targetFolder to (choose file name) as text

      set targetPath to targetFolder & "New"

       

      tell application "Adobe Photoshop CC 2017"

           tell current document

                activate    

               

                     set theDocument to current document

                     set exportOptions to POSIX file {class:save for web export options, transparency:true, web format:PNG, matte:true, png eight:false, with profile:true}

       

       

                     export theDocument in file targetPath as save for web with options exportOptions

       

           end tell

      end tell

       

      This won't work I get the error "Adobe Photoshop CC 2017 got an error: Can’t get current document of current document." number -1728 from current document of current document

       

      But if I take away export options part it will export with my previous export settings. So i saved my settings as a preset and changed my export options to set exportOptions to POSIX file "/Users/mileskelly/Library/Preferences/Adobe Photoshop CC 2017 Settings/Optimized Settings/JDO_PNG-24 Settings.irs". In the hope that point it to the settings file it would us my setting but I can't get it to work.

       

      Can anyone help me out?

       

      Thanks

      Miles K

        • 1. Re: Scripting Save for Web
          JavierAroche Level 3

          Hey MilesKelly97, try this:

          set targetFolder to POSIX path of (choose file name) as text

          set targetPath to targetFolder & "New.png"

           

          tell application "Adobe Photoshop CC 2017"

            activate

            set exportOptions to {class:save for web export options, transparency:true, web format:PNG, png eight:false, with profile:true}

            export current document in targetPath as save for web with options exportOptions

          end tell

          You had a matte:true in your save for web settings that was causing an error. Since you're exporting a png, you don't need a matte. I also converted the user's file name input to a POSIX path, since Photoshop requires that type of path to export.

           

          Also, I'm not sure why you're adding "New" at the end of the file name, but either way, I left that and just added a .png to the filename. Otherwise it would export without a file extension. You can make that generic if you want, depending on your export type.

           

          Hope it helps!