• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Need help with script for open random files from folder

New Here ,
Nov 01, 2018 Nov 01, 2018

Copy link to clipboard

Copied

Hello all,

I made an action in Photoshop to process files, but I'm stuck with one step, and that step must be executed by the script. I'm not familiar with scripting, so I'll be grateful if anyone here can help me.

I have a folder on the desktop with a lot of .jpg or .png files. I need a script to open two random files from that folder and put them on separate layers in my already opened document.

After that, the action will do the rest of the job.

TOPICS
Actions and scripting

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Contributor ,
Nov 01, 2018 Nov 01, 2018

Copy link to clipboard

Copied

How are your files named?

If they're 1.jpg 2.jpg etc then you can create a random (ish) loop.

If they're unique names like plant.jpg, fish.jpg then I don't believe it can be done. I could be wrong though.

Can you provide a bigger picture of what you're trying to achieve and why they need to be random.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 01, 2018 Nov 01, 2018

Copy link to clipboard

Copied

Yes, files are named with numbers, 001.jpg, 002.jpg ...

About what I try to achieve - I need to run batch processing to my files, but I can't import 3 files in one document with batch processing, so I open one file from another folder with action, and then I need to open two more files from the second folder with the script and put those files on layers so I can run rest of action on all of them.

And, another thing, they do not need to be random, I just thought it is simpler to write a script to take two random files from a folder because the script does not need to remember what files are loaded.

Another solution can be to load files like 001+002, than 003+004, 005+006... But I think this is a bad solution because I use batch processing, and do not know how a script can remember what files are loaded each time batch process run this action.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

I found this script on another forum, but it does not work, can someone help with this, please?

#target photoshop
var allImages = [“file path/img-1.jpg”, "file path/img-2.jpg", "file path/img-3.jpg"];
//this is a large array of file paths to 100 different images
var pickImage = allImages[Math.floor(Math.random() *
allImages
.length)];
var imgFile = File(pickImage);
var openFile = app.open(imgFile);
var secondImage = allImages[Math.floor(Math.random() * allImages.length)];
app
.activeDocument.artLayers.add(secondImage);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

What's the name of that forum? I want to see it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

LATEST

I don't know if it is allowed to post links to another forum?

javascript - Photoshop Script to Randomly Select Images - Stack Overflow 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines