Simple batch rotating of images

Hi Everyone,

Just wondering why this wont work (is very hot today - brain failing)

on open theFiles
tell application “Finder”
repeat with aFile in theFiles

		tell application "Image Capture Scripting"
			set this_image to open aFile
			rotate this_image to angle 90
			save this_image in aFile
			close this_image
		end tell
		
	end repeat
end tell

end open

Thanks kindly for any help

B

Change “Image Capture Scripting” to “Image Events” and you should be ok.

Oh, and you also need to change “open aFile” to “open contents of aFile”

Actually, the simple form of open aFile usually works just fine in Image Events. As long as the reference passed from the Finder is absolute, and it should be as written, you should not need to direct Image Events to open the contents of the file.

casdvm

Hi Guys,

Thanks for the prompt response.

Unfortunately it seems that I get the error

“the variable this_image is not defined”

Any further ideas?

Cheers

B

Okay, I actually tested your script, and I can confirm casdvm’s remarks. Anywho, when I tested it with multiple images it worked fine (I’m assuming you’ve saved it as a droplet/application) but when I put one image it got the message you describe. To fix it I just coerced theFiles to a list before the repeat loop.

set theFiles to theFiles as list

Also, while debugging, some weirdness happened. For whatever reason closing and re-opening the script editor seemed to make everything good again.

I just tried that and it is still giving me the same error. even when multiple files are dropped on it.

B

on open theFiles
set theFiles to theFiles as list

tell application "Image Events"
	repeat with aFile in theFiles
		set this_image to open aFile
		rotate this_image to angle 90
		save this_image in aFile
		close this_image
	end repeat
end tell

end open

I have no idea why, but it seems to work now:

on open theFiles
	set theFiles to theFiles as list
	repeat with aFile in theFiles
		tell application "Image Events"
			set this_image to open aFile
			rotate this_image to angle 90
			save this_image in aFile
			close this_image
		end tell
	end repeat
end open

All I did was move the Image Events tell block inside of the repeat loop. Very strange. I think it should have worked before, with the repeat inside of the tell.

casdvm

Something fishy is going on.

I compiled the exact script you posted as an application and dropped both 1 file and then 2 files onto it - and I still get the same error
“the variable this_image is not defined”

Very strange.

B

This is maddening. What version of OSX are you running? I know that Image Events had issues with 10.3.9, and only parts of it worked. After upgrading to 10.4, I have had no difficulties.

Also, I know this sounds strange, but have you installed the Developer Tools? I had some other weird glitches with both of my machines until I did that.

Keep posting until we get this solved, please.

casdvm

Thanks for being so helpful :slight_smile:

I have this machine running 10.4.2 and have the latest developer tools installed.

I actually created the original script using the script editors shortcut code additives by right clicking on the variable I wanted to manipulate.
Hence why I had tell application “Image Capture Scripting” instead of tell application “Image Events”

The most infuriating thing is that I have written something like this recently and don’t remember running into this problem.

Are we declaring these variables incorrectly?

B

FWIW, I too have had issues with Image Events.

Instead of trying to process the files in Image Events, try just moving them with the Finder, or writing the names to text files. That should tell you if it’s Image Events or not.

Anyway, through other posts here on Macscripter, some other alternatives for working with images have popped up you might want to check out:

Most recently, Photodrop for working with Image Events: 3000 miles from home | aram kudurshian's web site

iMagine by ktam:http://www.yvs.eu.com/

and lastly, take a look at ImageMagick!

-N

Hiya,

This works for me now! yay!
I think the alias thing has something to do with it :confused:

on open theFiles
	
	set theFiles to theFiles as list
	
	repeat with aFile in theFiles
		
		set aFile to aFile as alias
		
		tell application "Image Events"
			set theImage to open aFile
			rotate theImage to angle 90
			save theImage in aFile
			close aFile
		end tell
		
	end repeat
	
end open

Thanks so much for your help.

My next task will put in all the recursive jiggery pokery which will allow folders to be dropped in.

Out of interest - how do you use ImageMagick from within applescript?

Cheers

B

Image Magick can be called via the “do shell script” command.

-N