Skip to main content
Participant
October 22, 2024
Answered

Bulk Check images if they contain clipping paths without opening in Photoshop

  • October 22, 2024
  • 3 replies
  • 884 views

Hi all,

Is there any way we can check large number of  images if they contain clipping paths without having to opening each image in Photoshop. 

 

Thanks

This topic has been closed for replies.
Correct answer Stephen Marsh

This variation on my previous code will use native Mac/Win operating system commands to move the files (rather than copy and delete).

 

 

/*
THIS SCRIPT HAS NO GUARANTEE OR WARRANTY - USE AT YOUR OWN RISK!
*/

#target photoshop

if (confirm("Do you wish to move all files with no clipping paths to a new folder?")) {

    var folder = Folder.selectDialog("Select the folder with images");
    if (folder) {
        var files = folder.getFiles(/\.(psd|psb|tif|tiff|jpg|jpeg)$/i); // Adjust file types as needed
        for (var i = 0; i < files.length; i++) {
            var file = files[i];
            open(file);

            var doc = app.activeDocument;
            var hasClippingPath = false;

            // Check if there is any path in the Paths palette
            if (doc.pathItems.length > 0) {
                for (var j = 0; j < doc.pathItems.length; j++) {
                    if (doc.pathItems[j].kind == PathKind.CLIPPINGPATH) {
                        hasClippingPath = true;
                        break;
                    }
                }
            }

            // If the open file has no clipping path
            if (!hasClippingPath) {

                // Create new folder named "No Clipping Paths" in the path of the open image
                var noClipPathFolder = new Folder(file.parent + "/No Clipping Paths");
                if (!noClipPathFolder.exists) {
                    noClipPathFolder.create();
                }
                // Move the file to the new folder
                moveFile(file.fsName, noClipPathFolder + "/" + file.name);
            }

            doc.close(SaveOptions.DONOTSAVECHANGES);
        }

        app.beep();
        alert("Script completed!");

    }
}

function moveFile(from, to) {
    // With special thanks to William Campbell - willcampbell7
    // https://community.adobe.com/t5/photoshop-ecosystem-discussions/to-move-files-and-folders/td-p/8787869/page/3
    // from = String: full path and name of file to move.
    // to = String: full path and name of new file at destination.
    var command;
    var fileFrom;
    var fileTo;
    var folderTo;
    fileFrom = new File(new File(from).fsName);
    fileTo = new File(new File(to).fsName);
    if (/%(?!20|5C)/.test(File.encode(fileFrom.fsName))) {
        // Unicode characters detected in filename. Move will fail because
        // ExtendScript cannot pass Unicode text to command prompt via a string variable.
        return false;
    }
    if (!fileTo.exists) {
        folderTo = new Folder(fileTo.path);
        if (!folderTo.exists) {
            folderTo.create();
        }
        if (File.fs == "Windows") {
            command = "move \"" + fileFrom.fsName + "\" \"" + fileTo.fsName + "\"";
            app.system(command);
        } else if (File.fs == "Macintosh") {
            command = "mv \"" + fileFrom.fsName + "\" \"" + fileTo.fsName + "\"";
            app.system(command);
        }
        if (fileTo.exists) {
            return true;
        }
    }
    // Failed to move.
    return false;
}

 

 


This final variation simply logs the file paths and names to a text file, it doesn't move them.

 

/*
Log files with no clipping path to text file
*/

#target photoshop

var folder = Folder.selectDialog("Select the folder with images");
if (folder) {
    var files = folder.getFiles(/\.(psd|psb|tif|tiff|jpg|jpeg)$/i); // Adjust file types as needed

    var logFile = new File(folder + "/no_clipping_paths_log.txt");
    logFile.open("w");
    logFile.writeln("Files with no clipping paths:\n");
    logFile.close();

    for (var i = 0; i < files.length; i++) {
        var file = files[i];
        open(file);

        var doc = app.activeDocument;
        var hasClippingPath = false;

        // Check if there is any path in the Paths palette
        if (doc.pathItems.length > 0) {
            for (var j = 0; j < doc.pathItems.length; j++) {
                if (doc.pathItems[j].kind == PathKind.CLIPPINGPATH) {
                    hasClippingPath = true;
                    break;
                }
            }
        }

        // If the open file has no clipping path
        if (!hasClippingPath) {
            // Log the file
            logToFile(logFile, file.fsName + "\n");
        }
        doc.close(SaveOptions.DONOTSAVECHANGES);
    }
}

// End of script notification
app.beep();
alert("Logging completed. Check the file: " + logFile.fsName);

// Open the text file
logFile.execute();

function logToFile(logFile, text) {
    logFile.open("a");
    logFile.writeln(text);
    logFile.close();
}

3 replies

Stephen Marsh
Community Expert
Community Expert
October 31, 2024

@Ewan25138053xkt2 

 

Do you have any feedback on the scripts?

Stephen Marsh
Community Expert
Community Expert
October 22, 2024

I have 6 Bridge scripts from 2016-18, however, none work on modern versions of Bridge. One script did work with Bridge 2019.

 

It is possible to do this with ExifTool, and also with a Bridge script to run ExifTool. 

 

Here is the command line code for adding a Bridge blue "Review" label. There are other options, such as adding different metadata such as keywords, or adding rating stars, or renaming the file or moving the file to another folder:

 

exiftool -overwrite_original -if '$ClippingPathName' -label=Review -r 'top-level directory path to scan'

 

This command line example is for Mac which uses single straight quotes, Windows would use double straight quotes.

 

Just change the 'top-level directory path to scan' bit with the file system path to your folder.

Participant
October 22, 2024

Thank you @Stephen Marsh I will look into the ExifTool.

 

Thank you for taking the time to respond. Been trying to fin a solution to this for years.

Stephen Marsh
Community Expert
Community Expert
October 22, 2024

You're welcome, let me know if I can help further.

Stephen Marsh
Community Expert
Community Expert
October 22, 2024

There are scripts for Bridge or another method is via ExifTool. I'll post more info later when I'm in front of my computer. 

There are temporary working paths, saved paths and a saved path can also be set as a clipping path. How specific do you need this?

Participant
October 22, 2024

All I need to knnow if the images has a clipping path. Thats all