Can't Make Photoshop CS4 Save

I am using the following script to open a file, composite it via actions, then save it using the same name into another folder. I consistently get an error 8800 in the export step, and I get the same error by just using the export part of the code on a plain vanilla JPG file, so obviously something is wrong with my code, but I’ll be damned if I can figure it out.



set output_directory to "Mac HD 500:Users:alexanderstevens:Desktop:"
set picture_file to choose file with prompt "Select the Picture to Process"

tell application "Finder"
	set picture_name to name of (info for picture_file)
	set save_name to output_directory & picture_name
	
end tell

tell application "Adobe Photoshop CS4"
	activate
	do action "OPEN_ROAMING" from "NFL_ROAMING"
	open picture_file
	do action "ROAMING" from "NFL_ROAMING"

	-- Save
	set theExportOptions to {class:save for web export options, interlaced:true, quality:30, web format:JPEG}
	export document 1 in file save_name as save for web with options theExportOptions
	
end tell


Any help appreciated-

/A

What if you change «export» to «save»? I am using a line like follows in one of my scripts and it works in PS CS4:


save openimg in file tifffilepath as TIFF with options saveoptions

I found CS4 saving rather confusing too. Last time I asked about JPEG saving I got a number of answers that didn’t help, but apparently there are multiple ways of doing it. :wink:

I use this to save JPEGs, maybe it will give you some ideas:

save current document appending lowercase extension as JPEG in new_file_reference with options {embed color profile:false, format options:optimized, quality:JPEG_quality}

In theory you can leave-out the “with options” and “appending lowercase extension”.

“new_file_reference” has to be a “reference.” So when I was having my script build my paths…

set new_file_location to ((save_location as Unicode text) & "/" & new_file_name)

…I had to convert the finished path as a reference:

set new_file_reference to (a reference to file new_file_location)

For the record, I never got Save for Web to work with the control I needed. shrug Instead I have Photoshop explicitly prep as much as I can (stipping extra channels, converting to RGB, converting to 72dpi, etc.) so I could do a “save with options” which worked more reliably.

I have written a similar script that takes images dropped onto it, opens them in photoshop, samples them down to a given size in the long dimension, and then saves a copy as a JPEG to a folder set as a property.

When I upgraded the department that uses this script to CS4 recently, the script started throwing 8800 errors randomly. The error says either Photoshop encountered an EOF or the file is locked.

If you drag the same file onto the script a second time, the script will sometimes run successfully.

I will try suggestions above about converting to references and using UNICODE, but since this started with CS4, it appears to be related to that. Also annoying that the error is intermittent.

sorry, realized I should really post the code:


	tell application "Adobe Photoshop CS4"
						set {oru, ruler units of settings} to {ruler units of settings, pixel units}
						try
							activate
							open thisItem
							delay 1
							set this_image to current document
						
							set long_side to height of current document
							set long_side_identity to 1
							if width of current document > long_side then set long_side_identity to 2
							if width of current document > long_side then set long_side to width of current document
							if long_side > targetSize as integer and long_side_identity = 1 then
								resize image this_image height targetSize as integer
							end if
							if long_side > targetSize as integer and long_side_identity = 2 then
								resize image this_image width targetSize as integer resample method bicubic sharper
							end if
							-- Change document setting sof image always saves as a JPEG without dialog coming up
							
	set quick mask mode of this_image to false
							tell this_image
								delete (every channel whose kind is not component channel)
							end tell
tell this_image to flatten
							if (mode of this_image is not RGB) then
								change mode this_image to RGB
							end if
							if (bits per channel of this_image is sixteen) then
								set bits per channel of this_image to eight
							end if
							tell this_image
								
								set thePath to saveFolder & slug & shortName & ".jpg"
								save this_image in file thePath as JPEG with options {class:JPEG save options, quality:12, format options:optimized}
							end tell
							
							set this_image to current document
							tell this_image
								close
							end tell

This worked for me in CS3 and still works in CS4:

export current document in file (fullFilePathAsString & “.jpg”) as save for web with options {web format:JPEG, optimized size:true, quality:40, with profile:false}

I turned mine into a FaceSPan app, so the entire script is not very useful (FaceSpan-specific user interface bits), but here’s the main prepping/sizing/saving routines:

	--convert user answer to JPEG quality to Photoshop's numeric notation
	if JPEG_quality = "Medium" then
		set JPEG_quality to 5
	else
		if JPEG_quality = "High" then
			set JPEG_quality to 8
		else
			if JPEG_quality = "Maximum" then
				set JPEG_quality to 12
			end if
		end if
	end if
	
	--step through files
	repeat with i from 1 to count of items of g_dropped_items
		
		(* Needed only outside FaceSpan?
		set parseMeString to (item i of g_dropped_items) as string
		set parseMeStringPOSIX to POSIX path of parseMeString

		logMe("¢ POSIX Conversion Completed", 2)
		*)
		
		--get file name without extension
		tell (info for item i of g_dropped_items without size) to set {file_name, file_extension} to {name, name extension}
		set file_name to text 1 thru -((count file_extension) + 2) of file_name
		
		logMe("¢ File name without extension: " & file_name, 2)
		
		--rename file to indicate it was converted by script
		set new_file_name to file_name & file_suffix & ".jpg"
		
		logMe("¢ File name with extension: " & new_file_name, 2)
		
		try
			tell application "Adobe Photoshop CS4"
				
				my logMe("Photoshop Work Started", 3)
				
				activate
				open file (item i of g_dropped_items as string)
				--open file (parseMeStringPOSIX as text) --for outside FaceSpan
				
				--set document units to pixels (resize command only uses ppi)
				set ruler units of settings to pixel units
				
				--fix pixel aspect ratio
				set pixel aspect ratio of current document to 1.0
				
				tell current document
					--get height and width of current document
					set current_height to height
					set current_width to width
					
					--flatten image
					flatten
					
					--set image resolution
					resize image resolution file_res resample method none
					
					--if user requested inches, convert dimensions to ppi in-place (resize command needs ppi)
					if working_units is "Inches" then
						set new_height to (new_height * file_res)
						set new_width to (new_width * file_res)
					end if
					
					--change to RGB (CMYK not web compatible)
					change mode to RGB
				end tell
				
				--set background for padding (canvas resize)
				set background color to {class:RGB color, red:255, green:255, blue:255}
				
				--remove extra channels
				set safe_channels to {"Red", "Green", "Blue"}
				
				set channel_names to name of channels of current document
				
				repeat with c from 1 to number of items in channel_names
					if (item c of channel_names) is not in safe_channels then
						delete channel (item c of channel_names) of current document
					end if
				end repeat
				
				--figure out reduction percentages
				set height_ratio to new_height / current_height
				set width_ratio to new_width / current_width
				
				--make sure is not enlargement
				if (height_ratio < 1) or (width_ratio < 1) then
					
					--pick out smallest reduction and use that
					if height_ratio ≤ width_ratio then
						resize image current document height new_height resample method bicubic
					else
						if width_ratio < height_ratio then
							resize image current document width new_width resample method bicubic
						end if
					end if
				end if
				
				--pad image if required
				if pad_image is "Yes" then
					resize canvas current document width new_width height new_height anchor position middle center
				end if
				
				my logMe("¢ Image Padded (if needed)", 3)
				
				--create path to destination
				my logMe("¢ Build File Path and Name", 3)
				set new_file_location to ((save_location as Unicode text) & "/" & new_file_name)
				
				my logMe("¢ Destination Path Built: " & new_file_location, 4)
				
				--create reference (required for Photoshop saves)
				set new_file_reference to (a reference to file new_file_location)
				
				my logMe("¢ File Reference Created", 4)
				
				--save and close file
				save current document appending lowercase extension as JPEG in new_file_reference with options {embed color profile:false, format options:optimized, quality:JPEG_quality}
				close current document
				
				my logMe("¢ Save Completed", 3)
				
				--set completed file label to green
				tell application "Finder" to set label index of (item i of g_dropped_items) to 6
				
			end tell
			
		on error
			activate
			display alert file_name message "Unable to process this file, it will be skipped."
			
			--set uncompleted file label to red
			tell application "Finder" to set label index of (item i of g_dropped_items) to 2
		end try
	end repeat
	
	logMe("processFiles Ended", 0)
	
	quit application

Yes, I really do comment most of my scripts with this detail…I’m often very rushed, or doing scripts in 15-30 minute bursts then go weeks before getting back to them. I need the comments to jog my memory. :smiley:

The logMe entries reference my generic log-to-a-text-file routine, handy during troubleshooting, switched-off when I’m done.

The reason for the near-absurd level of stepping through removal of all that stuff is that Save for Web doesn’t quite “dejunk” files from Photoshop well enough for some unix-side database systems.

For example, our web group complained that the JPEGs I was giving them weren’t working because PHP/mySQL does not like the extraneous “resolution” information Photoshop embeds in JPEGs (among other things). Photoshop can save a “300dpi JPEG” but the JPEG technical standards apparently only allow for 72dpi…and PHP/mySQL are apparently very literal in this regard.

I found stripping all offending Photoshop elements and explicitly setting things like resolution solved the problem. Thus all the hoops I had to jump through, since we’re often converting complex, layered, high-res, multi-channel files.