Rotate if portrait

I’m new to Applescript, so forgive me for any dumbness…

I am trying to write an Automator script to rotate an image to the right if it is portrait, so I can batch process images for viewing on a PSP. In my main.applescript I have the following:

on run {input, parameters}
	
	set this_file to item
	try
		tell application "Image Capture Scripting"
			set this_image to open this_file
			set the image_width to the width of this_image
			set the image_height to the height of this_image
			if the image_width is greater than the image_height then 
				rotate this_image to angle -90
				save this_image in this_file
			end if
			close this_image
		end tell
	end try
	--	return input
end run

My questions:

  1. how do I do this for all items in the input
  2. why do I get an error “main.applescript:16: Expected end of line but found identifier”
    (I believe this refers to the line
 rotate this_image to angle -90

Thanks for any help you can give.

Thanks! I based the script off one in the Apple support area, but I guess it must have been old.