iView MediaPro Mail Script

iView MediaPro (as of when I'm writing this, version 2.6.2) is horrible about mailing photos. This AppleScript allows you to resize selected photos for mailing. It doesn't alter your originals.

Note: Do NOT copy/paste from this page, as it won't work due to a few invisible characters (due to iView's handling of rotation, see the rotation if/then's for the difference). Download the script here as a stuffit file. Feel free to read through here, as this is just a copy/paste of the script save those invisible characters.

Place this script in /Users/yourname/Library/Application Support/iView/Plug-ins/Scripts/ .

Open this script in Script Editor (Doesn't seem to work in 10.3, so download from the link above).

--- iView MediaPro photo mailer by Mitch Cohen, www.proactiveinteractive.com, mcohen (at) proactiveinteractive.com
--- Version 2004-08-28 8:02pm
--- Copyright 2004, licensed as open source freeware
--- Feel free to use and abuse as you wish.
--- Please give me credit if you use this in something else.
--- I don't think this will cause any harm, but can't guarantee it.
---
--- The basics:
--- Takes each selected image, resizes and rotates it using 10.2's Image Capture Scripting functions,
--- and saves the file in TemporaryItems (within /tmp).
--- Then attaches each file to Mail, adds filename and caption, then ends.
---
---Limitations:
--- Only works with OS X Mail. Doesn't work with Entourage, Eudora, etc.
--- Should be easy to modify if you use something else.
--- I believe this requires 10.2 or later. I've only tested on 10.3.
--- If you've flipped image in iView but haven't written the file back out, it'll just use the original image. If you've rotated but not flipped, it'll work fine.
--- I've only tested this with JPG files. It'll probably work with GIFs and TIFFs, but probably not much else. I'd like to get this to work with CRWs if possible at some point.
on run
set theSize to 480 --max height/width of scaled photo
display dialog "Set maximum image height/width:" default answer theSize
set theSize to (the text returned of the result) as number
set selectedItems to GetSelection()
set image_count to 0

repeat with theItem in selectedItems
tell application "iView MediaPro"

set theName to the name of theItem
set thePath to the path of theItem as string
set theRotation to the rotation of theItem as string
set theCaption to the caption of theItem as string
end tell
tell application "Finder"
set outfolder to path to temporary items folder as string
--what that returns ends in a colon
end tell

exportphoto(thePath, theName, outfolder, theSize, theRotation as string)
set image_count to image_count + 1
set this_file to outfolder & theName
set this_file to alias this_file

tell application "Mail"
if image_count = 1 then

--make the initial body
set theBody to return & return

activate
set theSubject to "Processing photos...please don't interrupt..."
set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return, visible:true}
end if

tell newMessage
tell content
make new attachment with properties {file name:this_file} at after paragraph ((count of paragraphs) - 2)
set paragraph ((count of paragraphs) + 0) to theName & ": " & theCaption & return & return & return & return
end tell
end tell
end tell

end repeat

tell application "Mail" --change the subject so the user knows you're done
tell content
tell newMessage
if image_count = 1 then
set subject to "A photo for you!"
else
set subject to (image_count as string) & " photos for you!"
end if
end tell
end tell
end tell

end run-- Image Capture Scripting function ----------------
on exportphoto(thePath, theName, outfolder, theSize, theRotation)

set this_file to (thePath)
set new_file to outfolder & theName

try
tell application "Image Capture Scripting"
set this_image to open file this_file
scale this_image to size theSize

if (theRotation = "ccw90") or (theRotation = "«constant ****then rotate this_image to angle 270
if (theRotation = "full180") or (theRotation = "«constant ****then rotate this_image to angle 180
if (theRotation = "cw90") or (theRotation = "«constant ****then rotate this_image to angle 90
--no way to handle flipping, so just skip it «»

save this_image in file new_file
close this_image
end tell
on error error_message
beep
display dialog error_message buttons {"Cancel"} default button 1
end try

end exportphoto-- get the selected media items in an array ---------------------------------------------
-- this function swiped from one of the iView sample scripts
on GetSelection()
set selectedItems to {}
tell application "iView MediaPro"
if window 1 exists then set selectedItems to the selection of window 1
end tell
if number of items in selectedItems is 0 then
display dialog ¬
"You need to select at least one media item in the front catalog in order to use this script." buttons {"OK"} default button ¬
"OK" with icon note giving up after 10
error number -128
end if
return selectedItems
end GetSelection