Applescript to crop images in Photoshop CS2

Hi I am trying to write an applescript to crop images. As an example, I have a 300 (width) x 200 (height) image and I want to resize it 120 x 60.

There is a “crop” command in the Applescript dictionary of Photoshop CS2 which has the following explanation:

crop document : the document object or objects to be operated upon
bounds list : area to crop (unit value)
[angle real] : angle of cropping bounds ( default: 0.0 )
[width real] : width of resulting document (unit value)
[height real] : height of resulting document (unit value)

I put in a command in my Applescript as follows

				[i]set docHeight to height
				set docWidth to width
				set newdocHeight to 60
				set newdocWidth to 120
				set variable1 to (docHeight - newdocHeight) / 2
				set variable2 to (docWidth - newdocWidth) / 2
				set variable3 to newdocHeight
				set variable4 to newdocWidth
				crop docRef bounds {variable1, variable2, variable3, variable4}}[/i]

But this produces an image 30 x 10 (not 120 x 60 which is what I want)!!

If anyone out there could give me some advice it would be much appreciated - thanks!


This works for me and crops the center most area of the image

set newWidth to 120
set newHeight to 60

tell application "Adobe Photoshop CS4"
	set {oru, ruler units of settings} to {ruler units of settings, pixel units}
	set docRef to front document
	tell docRef
		set docHeight to height
		set docWidth to width
		set XB1 to (docWidth - newWidth) / 2
		set XB2 to XB1 + newWidth
		set YB1 to (docHeight - newHeight) / 2
		set YB2 to YB1 + newHeight
	end tell
	crop docRef bounds {XB1, YB1, XB2, YB2}
	set ruler units of settings to oru
end tell