How to tell Photoshop where to save a file?

Now that I got the renaming of files working, I have another question that I could not find an answer to:

When the following part of my script is executed, we are inside a folder, and in this folder are image files (thisItem) and one subfolder with the name “thumbnails”. I want to open the image files in Photoshop, scale them etc., and then save the resulting thumbnail into the “thumbnails” folder located here inside the current containing folder. I cannot specify a fixed location to save to in my Photoshop action, because each folder I process has its own “thumbnails” folder, so I need to tell PS to use the present “thumbnails” folder.


tell application "Adobe Photoshop 7.0" -- yeah, I know, old stuff :-)
	activate
	open file (thisItem as text)
	do action "make thumbnails" from "my actions collection"
end tell

So how do I tell Photoshop where to save a file? Or, if this is not possible, how do I copy (not move! - I need the origninal file to remain unchanged) the files to the “thumbnails” folder and then open them from there?

AppleScript: 1.10.7
Browser: Firefox 2.0.0.1
Operating System: Mac OS X (10.4)

I have not scripted V7 of Photoshop but this should give you a good starting point for what you want. If you are calling action from script then be sure it has no open or save commands in it. Else you could just script your resize using docHeight & docWidth. Appending extension apperars broken in CS2 so just remove the {& “.jpg”} from new file path line.

set inputFolder to choose folder with prompt "Where is your top level folder" without invisibles
tell application "Finder"
	set filesList to (files of entire contents of inputFolder)
end tell
--
tell application "Adobe Photoshop CS2"
	activate
	set display dialogs to never
	set UserPrefs to properties of settings
	set ruler units of settings to pixel units
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 FileCont to container of theFile
	end tell
	tell application "Adobe Photoshop CS2"
		open theFile
		set docRef to the current document
		tell docRef
			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
			delete (every channel whose kind is not component channel)
			delete every path item
			if (count of art layers) > 1 or (count of layer sets) > 0 or ((count of art layers) is 1 and not background layer of layer 1) then flatten
			set docHeight to height
			set docWidth to width
			if (docHeight ≥ docWidth) then resize image width 100 resolution 72
			if (docWidth > docHeight) then resize image height 100 resolution 72
			--
			-- do action here if you need it?
			--
			set docName to name of docRef
			set docBaseName to getBaseName(docName) of me
			set newFileName to (FileCont as string) & ":thumbnails:" & docBaseName & ".jpg"
			save docRef in file newFileName as JPEG with options ¬
				{quality:10} appending lowercase extension with copying
		end tell
		close current document without saving
	end tell
end repeat
--
tell application "Adobe Photoshop CS2"
	set ruler units of settings to ruler units of UserPrefs
end tell
--
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

Just cleaned up a few bits and bobs that weren’t needed. and added resize example.

Mark, thank you. I adapted your script and merged it with what I had, and it works like a charm.

By the way, there are Photoshop Scripting Guides online as PDFs for both PS7 and PS CS - I found them when I searched for an explanation of the options for saving JPEGs (which I didn’t understand, since they are named differently in my German version of PS). I don’t know if the locations are longterm, but if anyone is interested, I found the Guides here:

http://www.arch.usyd.edu.au/~adong/courses/desc9139/assets/PS7ScriptingGuide.pdf
http://partners.adobe.com/public/developer/en/photoshop/sdk/AppleScriptReferenceGuide.pdf

I guess the PS7 guide can be found on the Adobe website, too.

Scripting guides for Photoshop should exist in the application folder as part of the default install for CS1 & CS2 and may be earlier. CS2 has SFW which can be better for .jpg