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
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
...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...
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...
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"
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.
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.
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
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
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.
Copy link to clipboard
Copied
I have some other code from SuperMerlin for moving files based on other criteria, if that would help.
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.
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!
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.
Copy link to clipboard
Copied
.
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;
};
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
Copy link to clipboard
Copied
Thank you SuperMerlin, much better than a copy/remove step that Photoshop would have performed.
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.
Copy link to clipboard
Copied
Excellent. Thank you VERY much!
Copy link to clipboard
Copied
Moderator, please move this thread to Bridge Scripting
Copy link to clipboard
Copied
Moved to the Bridge Scripting forum, from the Photoshop forum.