changing resolution of image files via applescript

I was actually looking for automator to be able to do this, but it looks like it can only scale. I’d like to be able to run this applescript on a folder, to where it opens up each item in say Preview, and changes the resolution to X dpi and the image to 256 colors. I’d also like to be able to convert the images to RGB, but I don’t think Preview supports this.

Thoughts/suggestions/ideas/pointers?
Thanks

Check out the AS dictionary for Image Events with the Script Editor and roll your own. Doesn’t look like Automator includes Image Events as an application, but it can be scripted as one.

Speaking of Automator… running into some weird issues with it—

I set up a flow where a file is dropped in a hot folder (input folder) then simply copied to four subsequent folders. Each time I add a file to the hot folder, I get different results (sometimes it copies the file to 1, 2, 3, or all 4 folders). Any thoughts on why?

My Automator flow is setup such as “Get Folder Contents” → “Copy Finder Items [Folder 1]” → “Get Folder Contents” → “Copy Finder Items [Folder 2]” … and so on, with the script set as a folder action on the input folder.

Alternately I set it up to do “Get Folder Contents” → “Copy Finder Items [Folder 1]” → “Copy Finder Items [Folder 2]”… etc, and am getting the same mixed results each time.

I’ve never used Automator at all, and don’t know where to even begin diagnosing the actions and exchanges between them and Folder Actions (which I’ve started to use recently, but only sparingly). Sorry.

on run
	tell application "Finder"
		set the in_files to (every item of (choose folder))
	end tell
	scaleIt(in_files)
end run

on open the in_files
	scaleIt(in_files)
end open

on scaleIt(in_files)
	repeat with previewMe in the in_files
		try
			tell application "Image Events"
				set this_file to (POSIX path of (previewMe as alias))
				set this_image to (open file this_file)
				set target to 600 -- width or height, whichever is larger
				
				scale this_image to size target
				
				save this_image in this_file as JPEG --with icon
			end tell
		end try
	end repeat
end scaleIt

Image Events doesn’t know about “resolution” or “ppi” - only pixel dimensions. Something like this should work for your scaling. I don’t know how to change the color depth from 24 to 8 bit, but it should be possible.

I was able to get automator to reliably do this. Seems that after creating a workflow/script, you need to change it as per http://www.peachpit.com/articles/article.aspx?p=1215430.

Prior to doing this I was having reliability issues - where certain “triggered folder actions” would only work sometimes, or would work when I’d move an item to the trash (as opposed to when I copied the file into the hot folder), etc.

So essentially I teamed up automator, a free “Photoshop Automator Pack” and built some photoshop actions to do the job. It takes one master image, and outputs it now five different ways. Unfortunately, you must make sure to only have one file open/running an action in Photoshop at a time, otherwise the automation will try running on top of multiple images and end up not working or doing the wrong things to the wrong image. So unfortunately, you can’t “batch” drop in files, it’s limited to one at a time. But it should work for what I’m looking to do.

Thanks for the tips + help though.