Skip to main content
Known Participant
July 3, 2010
Question

Trying to use Applescript to save for web

  • July 3, 2010
  • 1 reply
  • 4092 views

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

This topic has been closed for replies.

1 reply

Muppet_Mark-QAl63s
Inspiring
July 4, 2010

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

Paul Riggott
Inspiring
July 4, 2010

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.

Muppet_Mark-QAl63s
Inspiring
July 4, 2010

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…