The Code
This hack shows off not only the Image Events technology used to script
the manipulation of images, but also the return of
Folder
Actions,
AppleScripts
triggered by touching a particular folder:
-- PDF to JPEG Auto-Converter
-- Author: Phil Ulrich
-- Purpose: Convert any number of PDFs dropped in a folder into JPGs
on adding folder items to this_folder after receiving filelist
tell application "System Events"
set these_files to (every file in this_folder whose name starts ¬
with "Picture" and (file type is "PDF " or name extension is "pdf"))
end tell
repeat with i from 1 to the count of these_files
set this_file to POSIX path of (item i of these_files as alias)
tell application "Image Events"
launch
set this_image to open file this_file
save this_image as JPEG in (this_file & ".jpg") with icon
close this_image
end tell
end repeat
end adding folder items to
Drop any files into the folder to which this script is attached and
it goes about making a list of files that begin with
Picture and end with pdf
(or that have the file type of PDF).
Anything matching this pattern is opened in another new Panther
built-in tool, Image Events (http://www.apple.com/applescript/imageevents).
Image Events exposes the built-in Scriptable Image Processing Server
(SIPS) and allow you to automate image manipulation in AppleScript.
Here, we're converting each PDF file to JPEG, adding
a preview of the image to the icon, and closing it. The original PDF
is left untouched.
I'm new to wonderful world of Mac OS X and as such not really up on Applescript. So, If anyone has any comments on this codes implementation. I'd appreciate it.