Is there any way to enable it to select multiple PDFs (or an entire folder with PDFs in it)?
The following should do the trick:
set sourceFolder to choose folder
set destinationFolder to POSIX file "/Users/Peter/Pictures/JPEGs" -- just an example; change the path to fit you needs
tell application "Finder" to set theFiles to files of the sourceFolder whose name extension is "pdf"
repeat with theFile in theFiles
tell application "Preview" to activate
tell application "System Events" to tell process "Preview"
opentheFile
set theName to displayed name of theFile
repeat until (window 1 whose name begins with theName) exists
delay 0.1
end repeat
keystroke "s" using {shift down, command down}
keystroke "d" using {command down}
tell pop up button 2 of group 1 of sheet 1 of window 1
click
clickmenu item "JPEG" of menu 1
end tell
keystrokereturn
if sheet 1 of sheet 1 of window 1 exists then
click button "Replace" of sheet 1 of sheet 1 of window 1
end if
repeat while sheet 1 of window 1 exists
delay 0.1
end repeat
end tell
tell application "Finder"
set {theName, theExtension} to {name, name extension} of theFile
tell me to set P to offset of theExtension in theName
set theName to text 1 through (P - 1) of theName & "jpg"
movefiletheName of desktopto the destinationFolder with replacing
end tell
tell application "Preview" to activate
tell application "System Events" to keystroke "w" using {command down}
end repeat
(I've also made the code somewhat more robust).
Message was edited by: Pierre L.