Converting PDFs to JPEGs in Photoshop

I am trying to get my script to open Photoshop and convert pdf’s to jpeg’s with the on adding items to folder event.
The script works well until the line I have in my code "display dialog “Check 4” . I have went through numerous related post in this forum trying to figure out what I have done wrong, and I just can’t seem to get it.

I realize this script is a little choppy. I have went on about 4 hours of sleep for over a week now. I have read through many applescripting guides and forums.

Any help is appreciated.

(*
ADD - NEW ITEM ALERT
�2002 Apple Computer

This Folder Action script is designed for use with Mac OS X version 10.2 and higher.

This Folder Action handler is triggered whenever items are added to the attached folder.
*)
–establish folders to be used

property dialog_timeout : 30 – set the amount of time before dialogs auto-answer.

on adding folder items to this_folder after receiving added_items

set outputFolder to “Macintosh_OS_X:Users:jeffreyd:Desktop:NewJPEGs:”

tell application “Finder”
activate
set filesList to every file in this_folder
end tell

tell application “Adobe Photoshop CS”
set display dialogs to never
close every document saving no
end tell

repeat with aFile in filesList
set fileIndex to 0
tell application “Finder”
set theFile to aFile as alias
set theFileName to name of theFile
end tell

tell application “Adobe Photoshop CS”
activate
open theFile as PDF
set docRef to the current document

– Convert the document to a document mode that supports saving as jpeg
if (mode of docRef is not RGB) then
change mode docRef to RGB
end if

set docName to name of docRef

set fileIndex to fileIndex + 1

set newFileName to (outputFolder as string) & docName 

set myOptions to �
{class:JPEG save options, embed color profile:false, quality:3, format options:standard, matte:none}

 display dialog "Check 4" My Script stops after this

save docRef in file newFileName as JPEG with options myOptions appending lowercase extension with copying 

display dialog "Get some rest"

close current document without saving
end tell

end repeat

end adding folder items to

This works fine for me, provided all the files in the folder are PDFs. I got rid of a bunch of extraneous code, Also, note my comments inline:

property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer. 

on adding folder items to this_folder after receiving added_items
    set outputFolder to (path to desktop as string) & "NewJPEGs:"
    tell application "Finder" to set filesList to files in this_folder -- are you sure this is what you want?
    --most folder action scripts would iterate through added_items (the new items), not every item.
    tell application "Adobe Photoshop CS"
        set display dialogs to never
        close every document saving no
        repeat with aFile in filesList
            activate
            open (aFile as alias) as PDF
            set docRef to current document
            tell docRef
                set docName to name
                set newFileName to (outputFolder & docName)
                if (mode is not RGB) then change mode to RGB
                set myOptions to {class:JPEG save options, embed color profile:false, quality:3, format options:standard, matte:none}
                display dialog "Check 4" giving up after dialog_timeout
                save in file newFileName as JPEG with options myOptions appending lowercase extension with copying
                close without saving
            end tell
        end repeat
    end tell
    activate
    display dialog "Now, get some rest." giving up after dialog_timeout
end adding folder items to

Jon

This is how I would use a script like this:

property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer. 

on adding folder items to this_folder after receiving added_items
    set outputFolder to (path to desktop as string) & "NewJPEGs:"
    set process_count to 0
    tell application "Adobe Photoshop CS"
        set display dialogs to never
        close every document saving no
        repeat with aFile in added_items
            if (aFile as string) ends with "pdf" then
                open (aFile as alias) as PDF
                set docRef to current document
                tell docRef
                    set docName to name
                    set newFileName to (outputFolder & docName)
                    if (mode is not RGB) then change mode to RGB
                    set myOptions to {class:JPEG save options, embed color profile:false, quality:3, format options:standard, matte:none}
                    save in file newFileName as JPEG with options myOptions appending lowercase extension with copying
                    close without saving
                end tell
                set process_count to process_count + 1
            end if
        end repeat
    end tell
    activate
    set the_plural to "s"
    if process_count = 1 then set the_plural to ""
    display dialog (process_count as string) & " PDF" & the_plural & " converted to JPEG. Now, get some rest." buttons {"OK"} default button 1 with icon 1 giving up after dialog_timeout
end adding folder items to

Jon

Thanks a bunch Jon for you help.

This is the first applescript I have ever put together. I am not sure if I have something else going on here or not, the script still stops at the “save in file” line. (I did start a new script with the revised script that you provided)

I have put something together that works, but, it does it by having me select the folder to process and not using the folder actions. I wanted to use the folder actions event just to make it as easy as possible.

If you have any other suggestions I am more than open to them.

I really do appreciate your time in helping me out.

Jeff

What happens when you use this script attached to a folder as a folder action script and drop some PDFs into the folder with the folder action script attached?

property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer. 
property target_folder_name : "NewJPEGs"

on adding folder items to this_folder after receiving added_items
    set outputFolder to (path to desktop as string) & target_folder_name & ":"
    try
        get outputFolder as alias
    on error
        tell application "Finder" to make new folder at desktop with properties {name:target_folder_name}
    end try
    set process_count to 0
    tell application "Adobe Photoshop CS"
        set display dialogs to never
        close every document saving no
        repeat with aFile in added_items
            if (aFile as string) ends with "pdf" then
                try
                    open (aFile as alias) as PDF
                    set docRef to current document
                    tell docRef
                        set docName to name
                        set newFileName to (outputFolder & docName)
                        if (mode is not RGB) then change mode to RGB
                        set myOptions to {class:JPEG save options, embed color profile:false, quality:3, format options:standard, matte:none}
                        save in file newFileName as JPEG with options myOptions appending lowercase extension with copying
                        close without saving
                    end tell
                    set process_count to process_count + 1
                on error the_error
                    tell me
                        activate
                        if button returned of (display dialog the_error buttons {"Copy to Clipboard", "OK"} default button 1 with icon 0 giving up after dialog_timeout) = "Copy to Clipboard" then set the clipboard to the_error
                    end tell
                end try
            end if
        end repeat
    end tell
    activate
    set the_plural to "s"
    if process_count = 1 then set the_plural to ""
    display dialog (process_count as string) & " PDF" & the_plural & " converted to JPEG. Now, get some rest." buttons {"OK"} default button 1 with icon 1 giving up after dialog_timeout
end adding folder items to

Jon

Jon,

Thanks a million. That script performed just as expected. I had put a lot of time into trying to get that to work. I have compared the “working script” against the “other script” and for me that really drives home the syntax and scripting that applescript expects.

This script will get put to work. Most importantly for me though is the better understanding I now have of using applescript.

Your volunteered time is appreciated more than you know.

I am going to spend some time looking over the working script for study material.

Thanks,

Jeffrey