Photoshop CS2 Save for web for selected item in finder (or bridge)

I’m trying to figure out a way to save for web out of PS CS2 and I’m having mixed results.

I can get the script to save the file as jpeg, but it keeps the name of the original tif file. I’d like to be able to get the name without the extension.

Here is what I have…


property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "pct"}

tell application "Finder"
	activate
	try
		set these_items to the selection
		repeat with i from 1 to the count of these_items
			set this_item to item i of these_items
			if the file type of this_item is in the type_list or ¬
				name extension of this_item is in the extension_list then
				set this_path to this_item as string
				set thisFile to this_item as alias
				tell application "Adobe Photoshop CS2"
					activate
					set ruler units of settings to pixel units
					open thisFile showing dialogs never
					--set myOptions to {class:JPEG save options, embed color profile:false, quality:7}
					--set myExportOptions to {«class fltp»:JPEG, quality:40}
					set myOptions to {class:save for web export options, as:JPEG, quality:60}
					-- Run Photoshop action to USM, convert to CMYK
					set docRef to current document
					
					--resizing images proportionaly and non proportionaly scaled
					resize image docRef width (90) height (90) resolution (72) resample method bicubic sharper
					export docRef as save for web with options myOptions in file (thisFile as string) --appending lowercase extension
					--save docRef as JPEG with options myOptions in file (thisFile as string) appending lowercase extension
					close current document saving no
					
				end tell
			end if
			
		end repeat
	on error error_message
		display dialog error_message buttons {"OK"} default button 1
	end try
end tell

Note that if you want the script to compile you have to change the {class:save for web export options, as:JPEG, quality:60} with {class:save for web export options, «class fltp»:JPEG, quality:60}. This was mention in another thread.

This is realy annoying, so if anybody has a solution for this, it would be great.

The final goal here is to be able to save 2 copies of each file in the same path they are right now. So for exemple if I have…

Folder1
Folder1_1
image1.tif
image2.tif
image3.tif
image4.tif
Folder1_2
image1.tif
image2.tif
image3.tif
image4.tif
Folder1_3
image1.tif
image2.tif
image3.tif
image4.tif

I’d like to be able to save those jpeg in each of those folders. The name of the image are the same from one folder to the other. I’d use the save for web because it gives me much smaller file size then just save as jpeg which I could do with Russel brown’s services. I’d also like to rename the image file as image1.jpg and image1t.jpg. The first having a resize of 470 pixel and the second one would be a thumbnail at 90 pixel.

If you have a script that will do that please post it here. If you know how to do part of it or just want to help, please do:-)

TIA
Jeff

OK, here’s another version which doesn’t work either but I think it’s closer to what I want. As a first step anyway…


property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "pct"}

tell application "Finder"
	activate
	try
		set these_items to the selection
		repeat with i from 1 to the count of these_items
			set this_item to item i of these_items
			if the file type of this_item is in the type_list or ¬
				name extension of this_item is in the extension_list then
				tell application "Adobe Photoshop CS2"
					activate
					
					set this_path to this_item as string
					set this_file to this_item
					-- get the parent folder of the image file
					set the parent_folder to the container of this_file
					-- derive new name for the new image file
					set the new_name to my add_extension(this_file, "jpg")
					-- look for an existing file
					if (exists file new_name of the parent_folder) then
						error "A file named "" & new_name & "" already exists."
					end if
					
					set ruler units of settings to pixel units
					open this_file showing dialogs never
					--set myOptions to {class:JPEG save options, embed color profile:false, quality:7}
					--set myExportOptions to {«class fltp»:JPEG, quality:40}
					set myOptions to {class:save for web export options, as:JPEG, quality:60}
					-- Run Photoshop action to USM, convert to CMYK
					set docRef to current document
					
					--resizing images proportionaly and non proportionaly scaled
					resize image docRef width (90) height (90) resolution (72) resample method bicubic sharper
					export docRef as save for web with options myOptions in file new_name of the parent_folder --appending lowercase extension
					--save docRef as JPEG with options myOptions in file (thisFile as string) appending lowercase extension
					close current document saving no
					
				end tell
			end if
			
		end repeat
	on error error_message
		display dialog error_message buttons {"OK"} default button 1
	end try
end tell

on add_extension(this_file, new_extension)
	set this_info to the info for this_file
	set this_name to the name of this_info
	set this_extension to the name extension of this_info
	if this_extension is missing value then
		set the default_name to this_name
	else
		set the default_name to ¬
			text 1 thru -((length of this_extension) + 2) of this_name
	end if
	return (the default_name & "." & the new_extension)
end add_extension

I get an error saying can’t get file document file 1.tif

This code is a mess, I’m trying to cut and paste parts and bits from Apple’s site, this site, and modify them, but I can’t figure it out. Thanks for any help.

Jeff

Jeff, I see you have also posted over at Adobe’s site and have changed your request slightly to make use of the supplied batch script. I have many variations based on this script mostly for converting print based graphics down to web suitable stuff. Here is some code that works just fine for me. There is no filtering of any of the files to check if PS can open them but in my case I know that Im running in image only folders so its not required. You should be able to exchange the Saves to Exports (you know the bug fix) for use with CS2 and it’s SFW. I don’t have CS2 so you’ll have to get your hands dirty but that’s all part of the fun. The bones should be OK. There is also a bug with the resize in CS2 but if your using pixels @ 72dpi then you can ignor this issue for now. Hope this helps.

set inputFolder to choose folder with prompt "Pick your TOP level folder!"
--
tell application "Finder"
	set filesList to (files of entire contents of inputFolder)
end tell
--
repeat with aFile in filesList
	set fileIndex to 0
	tell application "Finder"
		set theFile to aFile as alias
		set theFileName to name of theFile
		set the subFolder to the container of theFile
	end tell
	--
	tell application "Adobe Photoshop CS"
		activate
		set UserPrefs to properties of settings
		set ruler units of settings to pixel units
		--
		open theFile showing dialogs never
		set docRef to the current document
		tell docRef
			set docName to name of docRef
			set docBaseName to getBaseName(docName) of me
			if (mode is not RGB) then
				change mode to RGB
			end if
			if (bits per channel is sixteen) then
				set bits per channel to eight
			end if
			-- You may want this!
			delete (every channel whose kind is not component channel)
			-- You may want this!
			delete every path item
			-- If you want this USM below then set the options
			filter current layer using unsharp mask with options ¬
				{amount:130, radius:3, threshold:10}
			--
			--set myOptions to {class:JPEG save options, embed color profile:false, quality:7}
			--set myExportOptions to {«class fltp»:JPEG, quality:40}
			--resizing images proportionaly and non proportionaly scaled
			--
			resize image height 400 resolution 72 resample method bicubic sharper
			set newFileName to (subFolder as string) & docBaseName & "_L"
			save docRef in file newFileName as JPEG with options ¬
				{quality:9} appending lowercase extension with copying
			--
			resize image height 200 resolution 72 resample method bicubic sharper
			set newFileName to (subFolder as string) & docBaseName & "_M"
			save docRef in file newFileName as JPEG with options ¬
				{quality:9} appending lowercase extension with copying
			--
			resize image height 100 resolution 72 resample method bicubic sharper
			set newFileName to (subFolder as string) & docBaseName & "_S"
			save docRef in file newFileName as JPEG with options ¬
				{quality:9} appending lowercase extension with copying
		end tell
		--
		close current document saving no
		--
		set ruler units of settings to ruler units of UserPrefs
		--
	end tell
end repeat
--
on getBaseName(fName)
	set baseName to fName
	repeat with idx from 1 to (length of fName)
		if (item idx of fName = ".") then
			set baseName to (items 1 thru (idx - 1) of fName) as string
			exit repeat
		end if
	end repeat
	return baseName
end getBaseName

As far as the “as:JPEG” bug, I found this somewhere else on this site a while back to fix it. Add this to the top of your script:

on compileAsOption(valStr)
	tell application "Adobe Photoshop CS2"
		run script "tell application \"Adobe Photoshop CS2\" to return {«class fltp»:" & valStr & "}"
	end tell
end compileAsOption

And then change this line:

set myOptions to {class:save for web export options, as:JPEG, quality:60}

to:

set myOptions to {class:save for web export options, optimized size:true, quality:60, with profile:false} & my compileAsOption("JPEG")   --I added a couple of additional options I use. Feel free to delete if you don't want them

This basically fixes the bug each time you run the script, which is a little goofy but the only way I know around this problem.

Model: G5 Tower (not Intel) - Script Editor ver 2.1.1
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Thanks guys, I knew I could count on this community to come thru my my scripting needs:-)

I’ll check them out and will post any question if any. I’ll be very busy retouching lots of image in the next few weeks, so I probably won’t have time before that, but rest assured that I really appriciate it.

Thanks again
Jeff