Really need some help with a photoshop script

This is what I am trying to do. I am trying to open a file, create a specific layer, and leave it open. Then open another image / select all / copy and then paste the contents of the clipboard to a specific layer on the first document on the layer called ImageLayer. I think I am getting close, but the paste is not pasting on the correct document. It is pasting it back on top of where it is copying it from. After that I am going to need to set that image to the bottom of the stack. I have no idea how to do that.

Summary of what I need help with:
I need to know how to paste the contents on the clipboard to a specific layer on a document that was opened previously.
I need to know how to reorder the layers inside a document.

This is what I have so far.


tell application "Adobe Photoshop CS2"
	set myProof to choose file {} without invisibles
	set docref to myProof
	open docref
	set docref to current document
	tell docref
		set FileNameLayer to make new art layer at beginning with properties {name:"ImageLayer"}
	end tell

	set myPic to choose file {} without invisibles
	set picref to myPic
	open picref
	set picref to current document
	tell picref
		select all
		copy
	end tell
	tell docref
		paste
	end tell
end tell


Bighoss, don’t bother yourself with the clipboard C&P Photoshop supports duplicate to target this includes layers between docs. Here is a script of mine that does this as batch process on selected folders with a bit more than you requested but you are welcome to strip out the relevant parts.

set inputFolderA to choose folder with prompt "Select a folder of images that you want at the bottom of your files?"
set inputFolderB to choose folder with prompt "Select a folder of images that you want at the top of your files?"
set outputFolder to choose folder with prompt "Select a folder to save the new images to?"
--
tell application "Finder"
	set filesListA to files in inputFolderA
	set countA to count of files in folder inputFolderA
	set filesListB to files in inputFolderB
	set countB to count of files in folder inputFolderB
	if (countA) ≠ (countB) then display dialog "You have an uneven amount of pictures!!! check your folders and try again."
end tell
--
repeat with i from 1 to countA
	tell application "Finder"
		set theFileA to item i of filesListA as alias
		set theFileB to item i of filesListB as alias
	end tell
	--
	tell application "Adobe Photoshop CS"
		activate
		set display dialogs to never
		set UserPrefs to properties of settings
		set ruler units of settings to pixel units
		set background color to {class:RGB color, red:255, green:255, blue:255}
		set foreground color to {class:RGB color, red:0, green:0, blue:0}
		--
		open theFileA
		set docRefA to the current document
		set docHeightA to height of docRefA -- This is for if you require some repositioning!!!
		set docWidthA to width of docRefA -- This is for if you require some repositioning!!!
		--
		open theFileB
		set docRefB to the current document
		tell docRefB
			set docHeightB to height of docRefB -- This is for if you require some repositioning!!!
			set docWidthB to width of docRefB -- This is for if you require some repositioning!!!
			set docName to name of docRefB
			set docBaseName to getBaseName(docName) of me -- Getting the name of the second file to use for layer name
			duplicate layer 1 to beginning of docRefA
		end tell
		close docRefB without saving
		--
		tell docRefA
			set properties of layer 1 to ¬
				{name:docBaseName, blend mode:multiply, opacity:50.0} -- Here are options for name, mode & opacity
			set docName to name of docRefA
			set docBaseName to getBaseName(docName) of me
			set newFileName to (outputFolder as string) & docBaseName & "_Mixed" -- You new files naming.
			save docRefA in file newFileName as Photoshop format with options ¬
				{class:Photoshop save options, save alpha channels:true, save spot colors:true, embed color profile:true, save layers:true} ¬
					appending lowercase extension with copying
		end tell
		close current document without saving
		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

Had a bit of time to look at what you wanted. This should be closer to what you want now.

set MyFileA to choose file with prompt "Select an image that you want at the bottom of your file?" without invisibles
set MyFileB to choose file with prompt "Select an image that you want at the top of your file?" without invisibles
--
tell application "Finder"
	set MyFileA to MyFileA as alias
	set MyFileB to MyFileB as alias
end tell
tell application "Adobe Photoshop CS"
	activate
	open MyFileA -- Open the file that goes on the bottom.
	set docRefA to the current document -- Set a reference to this open doc.
	--
	open MyFileB -- Open the file that goes on the top.
	set docRefB to the current document -- Set a reference to this open doc.
	tell docRefB
		duplicate layer 1 to beginning of docRefA -- Duplicate between open doc references.
	end tell
	close docRefB without saving
	--
	tell docRefA
		set properties of layer 1 to ¬
			{name:"ImageLayer"} -- Here is where you name the layer
	end tell
end tell

Mark67 - that first post showed me exactly what I needed and I was able to pull out the pieces to make it work like a champ. One goofy question about PS - I am working on an iMac at home and the script works like a champ, but when we run it at the office on the laptop or quad PS is putting some goofy comments on the file that my iMac was not. I am sure this is some kind of setting inside PS, but I need it to stop doing that. Do you know what that could be?

bighoss, can you give me a better explanation of “goofy comments” and where you are getting them? Im a CS1 user on OSX.3.9 so there may be a few parts of the script that need wording slightly different with CS2 also are your machines the same OS set up, I can’t help with that until I get upgraded and can test for myself. Posting your edited version of the script would be the biggest help.