Photoshop 2020 Script for sorting photos into separate folders for landscape, portrait and square

Explorer ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

Hi

 

I often have 1000s of photos in a folder that I would like to copy or move to three folders according to whether the photo is landscape, portrait or square. I've searched but can't find a script. I know I can do this manually using Bridge filters but it would be really useful to be able to click a script to carry out the task.

 

As an aside, the Bridge filter has a tolerance on what it determines to be square so it filters photos that are nearly square. I'm after filtering photos that are exactly square.

 

Thanks in advance for any advice that can be given, Leo

TOPICS
Scripting

Views

1.4K

Likes

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

Guide , Mar 18, 2020 Mar 18, 2020

Here is a Bridge script that should sort the documents.

It will create Landscape, Portrait and Square folders off the selected folder.

To use: select the documents, Tools - "Sort Landscape - Portrait - Square Pics"

The script must be a plain text document with a .jsx extension.

Place the script in the correct folder, this can be found by going to the preferences - Startup Scripts - then click the button "Reveal My Startup Scripts" this will open the folder where the script is to reside.

Once placed r

...

Likes

Translate

Translate
Community Expert ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

As a Photoshop scripting beginner, I have some ideas and believe that there may be some limitations in Photoshop, however, I think that a script in Adobe Bridge would be a better place to do this. Bride scripts are much harder for me than Photoshop, so you could make a new post in the Bridge forum tagged as a scripting question.

 

Now I can offer you a solution using ExifTool if you are willing to use a command-line interface as the coding is so much easier...

 

 

 

Likes

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 ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

The following ExifTool code will add a Bridge Label to each image type:

 

 

exiftool -if '$imagewidth > $imageheight' -label='Review' -execute -if '$imagewidth < $imageheight' -label='Select' -execute -if '$imagewidth == $imageheight' -label='Approved' -common_args -overwrite_original '/Users/username/Desktop/my folder full of images'

 

 

Select = Portrait

Approved = Square

Review = Landscape

 

Note: Windows users would need to change the single straight quotes for double straight quotes and use the appropriate file path to the folder to process.

 

You can then manually filter and move based on the label in Bridge.

 

I'll add some further code later to automatically move the files to new folders...

Likes

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 ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

Here is the ExifTool Windows code to move images:

 

 

 

exiftool -if "$imagewidth > $imageheight" -directory=%d"Landscape Images" -execute -if "$imagewidth < $imageheight" -directory=%d"Portrait Images" -execute -if "$imagewidth == $imageheight" -directory=%d"Square Images" -common_args "C:\Users\username\Desktop\my folder full of images"

 

 

 

Screen Shot 2020-03-18 at 18.29.27.png

 

 

Mac OS Code to move images:

 

 

 

exiftool -if '$imagewidth > $imageheight' -directory=%d'Landscape Images' -execute -if '$imagewidth < $imageheight' -directory=%d'Portrait Images' -execute -if '$imagewidth == $imageheight' -directory=%d'Square Images' -common_args '/Users/username/Desktop/my folder full of images'

 

 

 

Screen Shot 2020-03-18 at 18.32.02.png

All you need to do is change the path to the target folder at the end of the code. I only used 3 images in this example, so your list will be a little longer.

Likes

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 ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

Thanks for your help Stephen. I didn't know scripts could be run in Bridge. I'm not familiar with ExifTool. I was hoping that someone may have written a Photoshop vbscript or javascript that would analyze each photo and copy or move them to one of three folders. 

Likes

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 ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

If you are unfamiliar with the Windows CMD prompt or Terminal.app on the Mac and/or ExifTool:


changing UPPER to lowercase keywords in Bridge or Lightroom

 

Drag items into a Terminal window on Mac

 

Working from the command line

 

Getting started: Command-line ExifTool in Windows


I'm not sure that Photoshop scripting can directly move files, only copy files and then possibly delete the originals... A more advanced scripter than me could answer that question.

 

I still believe that Bridge is better suited to this task than Photoshop is, as Bridge is a file browser and manager... That being said, Photoshop could be used to run such a script where all one needs to do is hard code or select a folder to get a result.

 

Here is a link to a topic that contains code to shuffle files in Photoshop that could be altered:

 

Rename file, delete "_abc1234" and save to processed folder

 

Bridge has many useful scripts written for it, however, fewer people know how to script Bridge than say Photoshop.

 

More here on installing scripts:

 

Downloading and Installing Adobe Scripts

 

 

Likes

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 ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

I haven't done much with Bridge scripting either, but I can be done, and I think without exiftools. You should be able to get the image's dimension, but I'll have to try later. And I believe moving a file is a matter of first copying the file to a new location, then deleting the old file.

Likes

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 ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

I have some other code from SuperMerlin for moving files based on other criteria, if that would help.

Likes

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 ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

Thanks Stephen. I was hoping that there would be a Photoshop vbscript or javascript that would do the trick so I can just click a script in Photoshop to get the job done.

Likes

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 ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

ExifTool is not hard to use in this case, install and then just paste the code into your CMD prompt or Terminal.app and hit enter/return and you are done!

Likes

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 ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

Thanks Chuck. I think I may have blurred things by saying "Move to". Moving or copying the files would be fine. I have updated my original post.

Likes

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 ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

.

Likes

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
Guide ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

Here is a Bridge script that should sort the documents.

It will create Landscape, Portrait and Square folders off the selected folder.

To use: select the documents, Tools - "Sort Landscape - Portrait - Square Pics"

The script must be a plain text document with a .jsx extension.

Place the script in the correct folder, this can be found by going to the preferences - Startup Scripts - then click the button "Reveal My Startup Scripts" this will open the folder where the script is to reside.

Once placed restart Bridge and accept the new script.

#target bridge   
   if( BridgeTalk.appName == "bridge" ) {  
sortPics = new MenuElement("command", "Sort Landscape - Portrait - Square Pics", "at the end of Tools");
}
sortPics.onSelect = function () { 
var sels = app.document.selections;
if(sels.length < 1) return;
var origFolder = decodeURI(app.document.thumbnail.spec);
var portFolder = Folder(origFolder + "/Portrait");
var landFolder = Folder(origFolder + "/Landscape");
var sqrFolder = Folder(origFolder + "/Square");
if(!portFolder.exists) portFolder.create();
if(!landFolder.exists) landFolder.create();
if(!sqrFolder.exists) sqrFolder.create();
app.synchronousMode = true;
for (var s =0;s< sels.length;s++){
var Thumb = new Thumbnail(sels[s]);
var Rotation = Thumb.rotation;
var Width = Thumb.core.quickMetadata.width * 1;
var Height = Thumb.core.quickMetadata.height *1;
if(Width ==0 || Height == 0) continue;
if(Width > Height && Rotation  == 0) Thumb.moveTo(landFolder);
if(Width < Height && Rotation  == 0) Thumb.moveTo(portFolder);
if(Width > Height && Rotation  != 0) Thumb.moveTo(portFolder);
if(Width < Height && Rotation  != 0) Thumb.moveTo(landFolder);
if(Width == Height) Thumb.moveTo(sqrFolder);
    }
app.synchronousMode = false;
};

Likes

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 ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

Thankyou, thankyou, thankyou. Absolutely brilliant. Thanks SuperMerlin. The scipt works a treat and is so much better than  what I was after as I can undertake the sort in any directory and don't have to think about making the sub folders. Once again thanks. Cheers Leo

Likes

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 ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

Thank you SuperMerlin, much better than a copy/remove step that Photoshop would have performed.

Likes

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
Guide ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

Yes Bridge is the way to go, allthough I go against a lot of people and use rename and this will move files using Photoshop, there could be exemptions, but if using the same disk and no alias etc. it should be fine and quick.

Likes

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 ,
May 12, 2022 May 12, 2022

Copy link to clipboard

Copied

LATEST

Excellent. Thank you VERY much!

Likes

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
LEGEND ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

Moderator, please move this thread to Bridge Scripting

Likes

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 ,
Mar 20, 2020 Mar 20, 2020

Copy link to clipboard

Copied

Moved to the Bridge Scripting forum, from the Photoshop forum. 

Likes

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