I want to create a script to crop the image into 5 different images of the same width.
suppose the image is 1000 x 400, I want the script to crop it in 5 parts of 200 x 400.
Said that, I have create this script:
tell application "Finder"
	
	set exportFolder to (path to desktop as text) & "cropCinco:"
	if (not (exists folder exportFolder)) then
		make new folder at desktop with properties {name:"cropCinco"}
	end if
	
end tell
set listFiles to {imagem1, imagem2, imagem3, imagem4, imagem5}
tell application "Adobe Photoshop CC 2014"
	activate
	
	set theDOC to the current document
	
	tell theDOC
		
		set docWidth to the width
		set docHeight to the height
		
		set fifth to docWidth / 5
		
		set xStart to 0
		set xFinal to docWidth - fifth
		set index to 1
		repeat 5 times
			
			set fileName to exportFolder & "image" & (index as string) & ".png"
			my cropDocAndExport(theDOC, xStart, 0, xFinal, 0, fileName)
			set xStart to xStart + fifth
			set xFinal to xFinal - fifth
			set index to index + 1
			
		end repeat
		
		
	end tell
	
end tell
on cropDocAndExport(doc, cropLeft, cropTop, cropRight, cropDown, nomeFicheiro)
	
	tell application "Adobe Photoshop CC 2014"
		activate
		
		tell doc
			set currentHistoryState to current history state
			
			crop current document bounds {cropLeft, cropTop, cropRight, cropDown}
			
			export it in nomeFicheiro as save for web with options {class:save for web export options, web format:PNG, transparency:true, png eight:false, interlaced:false, dither:none, quality:100}
			
			set current history state to currentHistoryState
			
		end tell
		
	end tell
	
end cropDocAndExport
The first crop parameter passed to the method is {0, 0, 800, 0}
It crashes on the crop line with this message: Adobe Photoshop CC 2014 got an error: File/Folder expected
if I change the crop line to
crop it bounds {cropLeft, cropTop, cropRight, cropDown}
then I have this error: Adobe Photoshop CC 2014 got an error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop. - Could not complete the command because the affected area is empty or does not overlap the canvas.
Any ideas?