Open Random Images of different Folders as Layers

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Kukurykus, Tom, xbytor

bburned
Posts: 2
Joined: Mon Mar 29, 2021 1:51 pm

Open Random Images of different Folders as Layers

Post by bburned »

Hello,

even if i work a lot with PS i am a beginner with scripting. I hope you can help me here with my topic:

I would like to open 1 random image of one Folder in PS.
I would like to open 1 random image of another Folder in PS.
I would like to open 1 random image of another Folder in PS.
Then i would like to collect these 3 random images as layers in one PS Document.

Do you have an Idea/Code/Scrip how I can achieve this?

Thanks a lot for your help!

User avatar
Kukurykus
Posts: 395
Joined: Mon Jul 25, 2016 12:36 pm

Re: Open Random Images of different Folders as Layers

Post by Kukurykus »

What would be images format, orientation, dimension and their resolution, the same for all?

bburned
Posts: 2
Joined: Mon Mar 29, 2021 1:51 pm

Re: Open Random Images of different Folders as Layers

Post by bburned »

Hi Kukurykus,

thank you for your reply!

Yes, all images will have same file type/format, orientation, dimension and resolution.

User avatar
Kukurykus
Posts: 395
Joined: Mon Jul 25, 2016 12:36 pm

Re: Open Random Images of different Folders as Layers

Post by Kukurykus »

Code: Select all

preferences.rulerUnits = Units.PIXELS, sTT = stringIDToTypeID;
(ref = new ActionReference()).putProperty(sTT('property'), gP = sTT('generalPreferences'))
ref.putClass(sTT('application')); (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref);
arr = ['placeRasterSmartObject', 'resizePastePlace']; dsc2 = new ActionDescriptor(); while(arr.length)
	dsc2.putBoolean(sTT(arr.shift()), false), dsc1.putObject(sTT('to'), gP, dsc2), executeAction(sTT('set'), dsc1)

dcmnt = documents.add(1, 1, 300, '', null, DocumentFill.TRANSPARENT, null, null, 'none')
runMenuItem(sTT('screenModeFullScreen')); for(i = 0; i < 3;) (dsc = new ActionDescriptor())
.putPath(sTT('null'), (fls = File('~/desktop/Folder/' + ++i).getFiles())[~~(Math.random() * fls.length)]),
executeAction(sTT('placeEvent'), dsc); dcmnt.revealAll(), runMenuItem(sTT('fitOnScreen')), togglePalettes()