Apple Script to resize photos from iPhoto

I did a search which turned out no useful results, so here we go.

I want to create an automator workflow which has to comprise an Apple Script that does resize the selected iPhoto images and passes those on to automator. I am a bloody beginner at Apple Script, so I appreciate any help.

cellar:

I can help with part of your script. This script will take the selected images from iPhoto and resize them to 50% of the original size, and then save the resized images to the desktop. The original images will be untouched.

--Rescales selected images in iPhoto and saves to desktop
tell application "iPhoto"
	set c to selection
	repeat with b from 1 to (count c)
		set ppa to (image path of item b of c)
		set ifn to image filename of item b of c
		set im_path to (POSIX path of ppa)
		my ReSize(im_path, ifn)
	end repeat
end tell

on ReSize(ph, x)
	set dk_path to path to desktop as Unicode text
	set save_im to dk_path & x
	tell application "Image Events"
		set q to open ph
		scale q by factor 0.5 --This number defines the amount by which to scale the image.
		save q in save_im
		close q
	end tell
end ReSize

I do not know anything about Automator, however, so I cannot help you to send the new images to an Automator flow. Perhaps someone else knows how to do that.

If you have any questions, or need this script altered, please say so.

casdvm

Thanks for the provided script. The only thing that is missing for my workflow is a command that the finder selects the scaled images, since the following Automator command is “get selected items”.

Since you’re working in Automator, why not use the provided iPhoto ‘Get Selected iPhoto Items’ action and then pass that to the Preview ‘Scale Images’ action? I tested it and it seems to do what you want. It even prompted me to put in a ‘Copy Finder Items’ action, so that the resized files ended up on the desktop.

I need the scaled images to be in an archive. That archive is to be attached to an e-mail, not the individual images. The problem I encounter is that the “create archive” command doesn’t produce any output, since it doesn’t recognize the output from “Copy Finder Items”.

The workflow can be found here:

http://axiom.gmxhome.de/workflow.zip

If someone knows what I’m doing wrong or how this can be solved, I’d greatly appreciate further help.

Ah, ok, I see the problem. All you have to do to fix it is drag a Finder ‘Get Specified Items’ action and drop it in between the ‘Scale Images’ action and the ‘Create Archive’ action. No configuration is necessary, just drop in that one step and you’ll be good as gold.

thumbs up! That did the trick, thank you very much.