Skip to main content
leol30
Known Participant
March 17, 2020
Answered

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

  • March 17, 2020
  • 6 replies
  • 3205 views

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

This topic has been closed for replies.
Correct answer SuperMerlin

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;
};

6 replies

Chuck Uebele
Community Expert
Community Expert
March 20, 2020

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

Kukurykus
Legend
March 18, 2020

Moderator, please move this thread to Bridge Scripting

Chuck Uebele
Community Expert
Community Expert
March 18, 2020

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.

Stephen Marsh
Community Expert
Community Expert
March 18, 2020

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

leol30
leol30Author
Known Participant
March 18, 2020

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.

Stephen Marsh
Community Expert
Community Expert
March 17, 2020

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"

 

 

 

 

 

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'

 

 

 

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.

leol30
leol30Author
Known Participant
March 17, 2020

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. 

Stephen Marsh
Community Expert
Community Expert
March 18, 2020

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

 

 

Stephen Marsh
Community Expert
Community Expert
March 17, 2020

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...

Stephen Marsh
Community Expert
Community Expert
March 17, 2020

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...