Description: A script that exports one (or more) images from iPhoto and via GraphicConverter ready to be inserted in a blog post for example.
Requirement: Mac OS 10.3.x and GraphicConverter
(* A script that exports one (or more) images from iPhoto and via GraphicConverter scale it to the user choosen value, cleans up the file name and save it as a small JPEG to the desktop. A tag for Drupals inline module is created and can via a dialog be placed on the clipboard. 2005-09-04 by Fredrik Jonsson <mailto(colon)fredrik(at)combonet(dot)se> home page <http://xdeb.org/wiki/AppleScript> *) tell application "iPhoto" activate try set the view to organize tab copy (my selected_images()) to these_images if these_images is false then error "Please select some images before using this script." -- Get image width set this_width to 0 repeat while this_width < 1 or this_width > 500 display dialog "Image width? (Must be 1 - 500)" default answer "" set this_width to text returned of result set this_width to this_width as integer end repeat set img_tags to "" repeat with i from 1 to the count of these_images set this_image to item i of these_images -- get the title of the photo set this_title to the title of this_image -- build image inline tag set img_tag to "[inline:" & i & "=" & this_title & "]" set img_tags to img_tags & img_tag -- clean title for file name set this_title to my change_case_of(this_title, "lower") -- get image paths and convert POSIX paths to alias references set this_file to the image path of this_image set this_file to (this_file as POSIX file) as alias -- fix and save the photo my processe_images(this_file, this_title, this_width) end repeat on error error_message number error_number if the error_number is not -128 then display dialog error_message buttons {"OK"} default button 1 end if return "user cancelled" end try end tell tell application "Safari" activate set script_result to (display dialog the "The image tag:" default answer img_tags buttons {"Cancel", "Clipboard"} with icon 1 default button 2) if the button returned of the script_result is "Cancel" then return else set the clipboard to img_tags end if end tell on processe_images(the_file, the_title, the_width) tell application "GraphicConverter" activate try open the_file tell window 1 set the_dim to image dimension set org_width to item 1 of the_dim set org_height to item 2 of the_dim set the_height to round ((the_width / org_width) * org_height) set image dimension to {the_width, the_height} unsharp mask radius 1 amount 60 threshold 1 set JPEG quality to 80 save in ((path to desktop as string) & the_title & ".jpg") as JPEG with wwwready and makeCopy close saving no end tell on error error_message display dialog error_message buttons {"Cancel"} default button 1 end try end tell end processe_images on change_case_of(this_text, this_case) if this_case is "lower" then set the comparison_string to " ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ" set the source_string to "_abcdefghijklmnopqrstuvwxyzaao" else set the comparison_string to " abcdefghijklmnopqrstuvwxyzåäö" set the source_string to "_ABCDEFGHIJKLMNOPQRSTUVWXYZAAO" end if set the new_text to "" repeat with thisChar in this_text set x to the offset of thisChar in the comparison_string if x is not 0 then set the new_text to (the new_text & character x of the source_string) as string else set the new_text to (the new_text & thisChar) as string end if end repeat return the new_text end change_case_of on selected_images() tell application "iPhoto" try -- get selection set these_items to the selection -- check for single album selected if the class of item 1 of these_items is album then error -- return the list of selected photos return these_items on error return false end try end tell end selected_images