Help needed with Photoshop and selections

I am after some help with this Photoshop script!

The aim of the script is to fill the background of an image a colour that is varied everytime. The background area is determined by a path within the Photoshop image which I would normally make into a selection manually and then fill with the colour required. I have looked into this and as far as I can tell you can’t make a selection from a path within AppleScript. The only way to “load” the selection is via a channel mask (I think!)

I have got the script to work as I need except the section with the channel selection. If you run the script you will see that it just fills the entire new art layer with the colour specified. No matter what I try it doesn’t seem to work properly (The image has a channel mask called “Outline Channel”)

set tempFolderName to "Temp"
set inputFolder to choose folder

tell application "Finder"
	set filesList to files in inputFolder
	if (not (exists folder ((inputFolder as string) & tempFolderName))) then
		set outputFolder to make new folder at inputFolder with properties {name:tempFolderName}
	else
		set outputFolder to folder ((inputFolder as string) & tempFolderName)
	end if
end tell

tell application "Adobe Photoshop 7.0"
	set display dialogs to never
	close every document saving no
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 cyanValue to text returned of (display dialog "Cyan Value?" default answer "" buttons {"Cancel", "OK"} default button 2 with icon 1)
		set magentaValue to text returned of (display dialog "Magenta Value?" default answer "" buttons {"Cancel", "OK"} default button 2 with icon 1)
		set yellowValue to text returned of (display dialog "Yellow Value?" default answer "" buttons {"Cancel", "OK"} default button 2 with icon 1)
		set blackValue to text returned of (display dialog "Black Value?" default answer "" buttons {"Cancel", "OK"} default button 2 with icon 1)
		
		
	end tell
	
	tell application "Adobe Photoshop 7.0"
		
		open theFile
		
		set docRef to the current document
		set myTiffOptions to {class:TIFF save options, image compression:LZW, byte order:Mac OS, save alpha channels:true, save spot colors:true, embed color profile:true, save layers:false}
		
		
		-- Convert the document to a document mode that supports saving as jpeg
		if (mode of docRef is not RGB) then
			change mode docRef to RGB
		end if
		if (bits per channel of docRef is sixteen) then
			set bits per channel of docRef to eight
		end if
		
		make new art layer in docRef with properties {blend mode:multiply}
		(* I am trying to load a selection from a channel and then fill the selected area with the colour specified by the user. This is as close as I've got -load docRef from channel "Outline Channel" combination type extended  *)
		select all docRef --I've included this so the script will run and very simply demonstrate part of what I'm after
		fill selection of docRef with contents {class:CMYK color, cyan:(cyanValue & ".0"), magenta:(magentaValue & ".0"), yellow:(yellowValue & ".0"), black:(blackValue & ".0")}
		
		set docName to name of docRef
		set docBaseName to getBaseName(docName) of me
		set newFileName to (outputFolder as string) & docBaseName & "-" & {"c" & cyanValue, "m" & magentaValue, "y" & yellowValue, "k" & blackValue}
		save docRef in file newFileName as TIFF with options myTiffOptions appending lowercase extension with copying
		
		--resize image and save as small version
		resize image current document width 10
		
		set docName to name of docRef
		set docBaseName to getBaseName(docName) of me
		set newFileName to (outputFolder as string) & docBaseName & "S-" & {"c" & cyanValue, "m" & magentaValue, "y" & yellowValue, "k" & blackValue}
		save docRef in file newFileName as TIFF with options myTiffOptions appending lowercase extension with copying
		close docRef without saving
		
	end tell
end repeat

-- Returns the document name without extension (if present)
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

I hope this all makes sense and any help would be most appreciated as I am very stuck!

Many thanks

I have included this line to try and solve my problem.

set current layer of docRef to layer "Layer 1" of docRef
load selection of docRef from channel "Outline Channel" of docRef combination type extended

Sadly it only came up with an error “Adobe Photoshop 7.0 got an error: The parameters for command ‘Add’ are not currently valid.” Does anyone know what this means?

:frowning:

try having the script tell photoshop to play a recorded action that will load a currently saved path?

tell application “Adobe Photoshop”
play action “load path” from “action folder”
end tell