Pierre L. wrote:
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 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-- the PDF file
tell me to set P to offset of theExtension in theName
set theName to text 1 through (P - 1) of theName & "jpg" -- the name of the JPEG file
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.
Hi Pierre--
Thanks for this, but it didn't work. Once I run it it requests for me to select a folder which I do and then it opens a "save as" option ... I save the file to another location, but then it gives me the following error. Ideas to fix this?:
error "System Events got an error: Can’t get sheet 1 of window 1 of process \"Preview\". Invalid index." number -1719 from sheet 1 of window 1 of process "Preview"
It seemed to me that the problem had something to do with preview, so I quit preview altogether and ran the script again. This time it seemed to work... however it only saved the first file within the folder as a jpeg to desktop, and then gave me this error:
error "Finder got an error: AppleEvent handler failed." number -10000
Ideas?