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

Script to set the biggest document (by file size) to active

New Here ,
Sep 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

Hello,

I am new to photoshop scripting and I am looking for a script that sets the biggest document, in terms of file size, to active and brings it to the front on photoshop. I am looking to do this because of the 'crop and straighten' function in photoshop. While batch cropping a thousand photos at a time, sometimes the 'crop and straighten' function crops an image into multiple documents. This isn't a problem, but sometimes then photoshop will perform this function and then set the active document to, for example, a piece of dust. In this example, photoshop will have cropped multiple documents from the original photo and the desired cropped document won't be set to active and instead a cropped image of dust. This doesn't happen too often, but in some cases could happen to maybe 10% of the batched images. To solve this problem, I would need photoshop to find the biggest document loaded in photoshop after it has performed the 'crop and straighten' function. I imagine it would set the original photo as active because that is still loaded, but that can be solved by closing that image first after the 'crop and straighten' is performed. Thank you for the help, everything is greatly appreciated. 

TOPICS
Actions and scripting

Views

568

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

correct answers 1 Correct answer

People's Champ , Sep 21, 2020 Sep 21, 2020
var old_units = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

var sizes = [];

for (var i = 0; i < app.documents.length; i++)
    sizes.push({size: app.documents[i].width.value * app.documents[i].height.value, idx:i});

sizes.sort(cmp);

function cmp(a, b)
    {
    if (a.size > b.size) return -1;
    if (a.size < b.size) return  1;

    return 0;
    }

app.preferences.rulerUnits = old_units;

app.activeDocument = app.documents[sizes[0].idx];  // open the largest docum
...

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

That would be a job for a file organizer Lightroom,Bridge, File Explorer, Finder.  Photoshop is not a file editor it edit document. It can save many image file formats from document

 

There is a script on the web the will batch process files through crop and straighten and save the new documents the crop and straighten creates. No document will remain open in Photoshop. Search for that script. I think that is what you need.

JJMack

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
Community Expert ,
Sep 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

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
People's Champ ,
Sep 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

var old_units = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

var sizes = [];

for (var i = 0; i < app.documents.length; i++)
    sizes.push({size: app.documents[i].width.value * app.documents[i].height.value, idx:i});

sizes.sort(cmp);

function cmp(a, b)
    {
    if (a.size > b.size) return -1;
    if (a.size < b.size) return  1;

    return 0;
    }

app.preferences.rulerUnits = old_units;

app.activeDocument = app.documents[sizes[0].idx];  // open the largest document

//app.activeDocument = app.documents[sizes[1].idx]; // open the second largest document

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 ,
Sep 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

This worked perfectly! Thank you so much. This will save me so much time and make batch cropping much more accurate.

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
Advocate ,
Sep 22, 2020 Sep 22, 2020

Copy link to clipboard

Copied

LATEST

little note:
If two of the files are the same size, you will unfortunately not receive any notice.

 

That could be a problem, but it doesn't have to be.

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