Script to insert image into existing PSD

Hello all, been using this site as a resource for a while now, but this is my first time posting.

Basicly, I’m trying to automate the creation of student IDs. I have the script set up to get all the relevant information from a database, and drop it into a photoshop template that I created. The wall I ran into is trying to automate the placing of the picture. I can’t for the life of me figure out how to get an image (probably a Jpeg, but if it’s important to know the exact filetype, I can ask) into the PSD at all. It would be best to be able to drop it into a specific layer, but right now, just getting it in the PSD at all would be a huge step. I have tried everything I can think of, but nothing is working.

Anyone have any ideas? Thanks in advance for any help. You guys are great.


Photoshop isn’t the ideal application for this purpose.
Actually InDesign is much more appropriate to this job.

Anyway, the AppleScript dictionary doesn’t provide any way to place a file,
but javascript does

set The_File to POSIX path of (choose file)

tell application "Adobe Photoshop CS3"
	tell current document
		do javascript "placeFile(); function placeFile() {function cTID(s) { return app.charIDToTypeID(s); }; var desc = new ActionDescriptor(); desc.putPath( cTID('null'), new File( '" & The_File & "' )); desc.putEnumerated( cTID('FTcs'), cTID('QCSt'), cTID('Qcsa') ); var ldesc = new ActionDescriptor(); ldesc.putUnitDouble( cTID('Hrzn'), cTID('#Pxl'), 0.000000 ); ldesc.putUnitDouble( cTID('Vrtc'), cTID('#Pxl'), 0.000000 ); desc.putObject( cTID('Ofst'), cTID('Ofst'), ldesc ); executeAction( cTID('Plc '), desc, DialogModes.NO );}" show debugger on runtime error
	end tell
end tell

You are the man. That worked perfectly. Thank you so much for your help.

By the way, I know Photoshop isn’t ideal for this, but thats what they’ve always been using so all the templates were basically created already. If I had to build from scratch I would have done Illustrator.

Stefan, that JavaScript is pretty much a recording of doing a menu item very much like you could do with system events. The benefit of the JavaScript is you don’t require a system preference to be active to use it. That a side you should have a new boolean in open class for smart object although I don’t have CS3 myself to see how it works.

I have no idea, what this javascript does exactly, I found it somewhere with google

It’s a cleaned up bit of Photoshop’s ScriptListener plug-in’s output. It records all that you do in Photoshop to a text log in action descriptor code.