Open 3 jpgs in Photoshop Document

Hello there. I have been trying to open 3 .jpg files from a selected folder in one Photoshop document, aligned one by one in a line. This is how I gotten so far:

tell application "Finder"
set fileFolder to choose files with prompt "Please select your files"
set fileList to every file in fileFolder as alias list
repeat with I form 1 to number of items in fileList

set myFile to(item I of fileList)
tell application "adobe"
open myFile

end tell
end repeat
end tell

It opens them in separate documents. I am trying to make it open in 1 document, arranged one by one. Any suggestions? Would be thankful

Hi Bioxent,

Welcome to MacScripter!

Yeah, it does look like the way you’ve written your script so far would result in it opening each jpeg in a separate document.

Are all the jpegs a common size?
What sort of size is the Photoshop document they’re going into?
Do they all need scaling in some way to fit in the new document?
If all the images are going into 1 document will each image be going on a separate layer?

Hello TecNik!
The Photoshop document can be any size, just so it could fit them on 1 screen, 1 document. Pictures have various sizes, but do not differ a lot from each other.
They can be scaled to same size if you can, it’s not necessary.
Yeah, each of them can go on a separate layer, that would be amazing.
What I need is to place them in a line, one by one, in one document, different or same layer.
Is there anything else? And can you do it? I would be really thankful for that.


There may be easier ways to achieve this, but this is the method I use.

property document_resolution : 300

on run
	display dialog "Please drop some images on the icon to run"
end run

on open (addedItems)
	set masterList to {}
	set overallWidth to 0
	set overallHeight to 0
	repeat with thisPath in addedItems
		set end of masterList to thisPath as text
		set PixelWidth to paragraph 2 of (do shell script "sips --getProperty pixelWidth " & (quoted form of POSIX path of thisPath) & " |  awk '/.*/ {print $2}' ") as integer
		set PixelHeight to paragraph 2 of (do shell script "sips --getProperty pixelHeight " & (quoted form of POSIX path of thisPath) & " |  awk '/.*/ {print $2}' ") as integer
		if overallHeight is less than PixelHeight then set overallHeight to PixelHeight
		set overallWidth to overallWidth + PixelWidth
	end repeat
	set countImages to (count masterList)
	if countImages is less than 2 then
		display dialog "Not enough images to create lineup" buttons {"OK"} default button 1 with icon note
	end if
	tell application "Adobe Photoshop CS6"
		set Newdoc to make new document with properties ¬
			{name:("Image_Lineup"), resolution:document_resolution, width:overallWidth as pixels, height:overallHeight as pixels, mode:RGB}
		set current document to Newdoc
		repeat with i from 1 to (count masterList)
			my openDupeAlign((item i of masterList), i, Newdoc)
		end repeat
		set alllayerlist to every art layer of current document
		my Select_Layers(Newdoc, ("Background"), "addToSelection")
		my alignToEdge("Rg")
		my Select_Layers(Newdoc, ("Background"), "removeFromSelection")
		my Select_Layers(Newdoc, ("Background"), "addToSelectionContinuous")
		my Select_Layers(Newdoc, ("Background"), "removeFromSelection")
		if countImages is greater than 2 then
			do javascript "var idDstr = charIDToTypeID( 'Dstr' );
    var desc76 = new ActionDescriptor();
    var idnull = charIDToTypeID( 'null' );
        var ref39 = new ActionReference();
        var idLyr = charIDToTypeID( 'Lyr ' );
        var idOrdn = charIDToTypeID( 'Ordn' );
        var idTrgt = charIDToTypeID( 'Trgt' );
        ref39.putEnumerated( idLyr, idOrdn, idTrgt );
    desc76.putReference( idnull, ref39 );
    var idUsng = charIDToTypeID( 'Usng' );
    var idADSt = charIDToTypeID( 'ADSt' );
    var idAdCH = charIDToTypeID( 'AdCH' );
    desc76.putEnumerated( idUsng, idADSt, idAdCH );
executeAction( idDstr, desc76, DialogModes.NO );"
		end if
		my Select_Layers(Newdoc, ("Background"), "addToSelectionContinuous")
		my alignToEdge("CV")
	end tell
end open

on Select_Layers(Doc_Ref, Layer_Ref, Add_Ref)
	-- Add_Ref = addToSelection, addToSelectionContinuous or removeFromSelection
	tell application "Adobe Photoshop CS6"
		tell Doc_Ref
			do javascript "Select_Layers(); function Select_Layers() { function cTID(s) { return app.charIDToTypeID(s); }; function sTID(s) { return app.stringIDToTypeID(s); }; var desc01 = new ActionDescriptor(); var ref01 = new ActionReference(); ref01.putName( cTID('Lyr '), '" & Layer_Ref & "' ); desc01.putReference( cTID('null'), ref01 ); desc01.putEnumerated( sTID('selectionModifier'), sTID('selectionModifierType'), sTID('" & Add_Ref & "') ); desc01.putBoolean( cTID('MkVs'), false ); executeAction( cTID('slct'), desc01, DialogModes.NO );};"
		end tell
	end tell
end Select_Layers

on openDupeAlign(openFile, layerName, targetDoc)
	tell application "Adobe Photoshop CS6"
		open file openFile
		set name of layer 1 of current document to layerName
		duplicate layer 1 of current document to beginning of targetDoc
		close current document without saving
	end tell
end openDupeAlign

on alignToEdge(edgeToAlign)
	tell application "Adobe Photoshop CS6"
		do javascript "var idAlgn = charIDToTypeID( 'Algn' );
    var desc36 = new ActionDescriptor();
    var idnull = charIDToTypeID( 'null' );
        var ref30 = new ActionReference();
        var idLyr = charIDToTypeID( 'Lyr ' );
        var idOrdn = charIDToTypeID( 'Ordn' );
        var idTrgt = charIDToTypeID( 'Trgt' );
        ref30.putEnumerated( idLyr, idOrdn, idTrgt );
    desc36.putReference( idnull, ref30 );
    var idUsng = charIDToTypeID( 'Usng' );
    var idADSt = charIDToTypeID( 'ADSt' );
    var idAd" & edgeToAlign & " = charIDToTypeID( 'Ad" & edgeToAlign & "' );
    desc36.putEnumerated( idUsng, idADSt, idAd" & edgeToAlign & " );
executeAction( idAlgn, desc36, DialogModes.NO );"
	end tell
end alignToEdge

Save it as a droplet and drop jpegs onto it. If the sizes of the images differ too much the distribution of images will be a bit odd.
Set your preferred resolution in the property at the top of the script
It will set your document to the combined width of the images and the maximum height, based on image data it gets from image events.