Skip to main content
Participant
October 8, 2022
Answered

Script to remove 'copy' from crop and straightened images.

  • October 8, 2022
  • 3 replies
  • 841 views

Hi I'm looking for a script that removes the word ' copy,' from files that have been cropped and straightened. Thanks.

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

I could rename afterwards using bridge or lupas rename which I have been doing but was hoping there was a way to script it in the action.


By @Joseph Brown

 

After the Action step for Crop and Straighten Photos, record the following script into the Action:

 

/*
Remove Copy from Open Doc Names.jsx
Stephen Marsh, 9th October 2022, v1.0
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-remove-copy-from-crop-and-straightened-images/td-p/13253044
Based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/cancel-suffix-number-addition-when-reopen-raw-filess-cr2/td-p/12904160
https://community.adobe.com/t5/photoshop-ecosystem-discussions/stop-photoshop-adding-number-suffixes-to-documents/m-p/12767371
*/

#target photoshop

// CHECK FOR OPEN DOCS
if (documents.length) {
    removeCopy();
    // WHY?
    removeCopy();
    // END OF SCRIPT
    app.beep();

// ALERT IF NO DOCS OPEN
} else {
    alert('You must have a document open!');
}

function removeCopy() {
    try {
        // IGNORE SAVED FILES
        app.activeDocument.path;
    } catch (e) {
        // LOOP OVER OPEN UNSAVED DOCS
        for (var i = 0; i < documents.length; i++) {
            activeDocument = documents[i];
            // PROCESS DOCS WITHOUT A FILENAME EXTENSION
            if (/\.[^\.]+$/i.test(activeDocument.name)) {} else {
                // PROCESS DOCS CONTAINING ' copy'
                if (activeDocument.name.match(/ copy/)) {
                    var origDoc = activeDocument;
                    var docName = origDoc.name.replace(/ copy/, '');
                    origDoc.duplicate(docName, false);
                    origDoc.close(SaveOptions.DONOTSAVECHANGES);
                }
            }
        }
    }
}

 

  1. Copy the code text to the clipboard
  2. Open a new blank file in a plain-text editor (not in a word processor)
  3. Paste the code in
  4. Save the text file as .txt
  5. Rename the file extension from .txt to .jsx
  6. Install or browse to the .jsx file to run (see below)

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

3 replies

Participant
October 8, 2022

I've got a few thousand objects shot with on a large black background and have created an action to select the object, crop and straighten with a 100px black border. I could rename afterwards using bridge or lupas rename which I have been doing but was hoping there was a way to script it in the action.

Earth Oliver
Legend
October 8, 2022

i'm sorry, but why is copy in their name to begin with? Very little of what you're doing here makes any sense. Just use Image Processor Pro or Batch to automate this task and you'll not have to rename anything after the fact.

Stephen Marsh
Community Expert
Community Expert
October 8, 2022
quote

i'm sorry, but why is copy in their name to begin with?


By @Earth Oliver

 

Because the File > Automate > Crop and Straighten Photos command duplicates the original file and appends a space+copy+space+digits on each image that is extracted and cropped and straightened.

 

The OP would simply like to streamline the workflow into a single step, rather than batch renaming the saved files as a second step.

Earth Oliver
Legend
October 8, 2022

how would any app know which images have been cropped and/or straightened?

Participant
October 8, 2022

I posted this question in the Photoshop ecosystem message board, so Photoshop is the app I'm using.

Stephen Marsh
Community Expert
Community Expert
October 8, 2022

@Joseph Brown – Is there a special reason why you need to do this in a Photoshop script?

 

After the fact, this is easy to do with Adobe Bridge's Batch Rename command.

 

Standard:

 

Find: copy

Replace:

 

(find a space followed by copy, replace with nothing to delete it).

 

 

With a regular expression –

 

Find:

(.+)( copy)(\.[^\.]+$)

 

Replace:

$1$3