• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script to invert colors, save new file by replacing a word in the filename

Community Beginner ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

Hi, I need a script that will select all on the canvas, invert colors, then save a new file by replacing the word "Black" with "White" in my filenames, as a Batch process.  I've only been able to create a Batch Action that will do everything but save out the new filename, and I assume that can only be done as a script?

 

Original Filename would be something like: Title_Logo_Black_RGB.eps

New Filename would be: Title_Logo_White_RGB.eps

 

Is there a way to include my action in the script and then run a "find and replace" string or something to switch out "Black" for "White" and then save?

TOPICS
Scripting

Views

351

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

Community Expert , Apr 15, 2022 Apr 15, 2022

Hi,

You can try below version

for (var i = app.documents.length - 1; i >= 0; i--) {
    var doc = app.documents[i];
    app.activeDocument = doc;
    var fileName = doc.fullName;
    app.executeMenuCommand('selectall')
    app.executeMenuCommand('Colors6')
    var saveOpts = new EPSSaveOptions();
    var _newFileName = fileName.fsName.replace('Black', 'White')
    doc.saveAs(File(_newFileName), saveOpts);
    app.executeMenuCommand('deselectall')
    doc.close( SaveOptions.DONOTSAVECHANGES);
}

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

Hi,

Try following snippet

for (var i = 0; i < app.documents.length; i++) {
    var doc = app.documents[i];
    var fileName = doc.fullName;
    app.executeMenuCommand('selectall')
    app.executeMenuCommand('Colors6')
    var saveOpts = new EPSSaveOptions();
    var _newFileName = fileName.fsName.replace('Black', 'White')
    doc.saveAs(File(_newFileName), saveOpts);
    app.executeMenuCommand('deselectall')
}

It will run for all the documents that are alreday open in the application

Best regards

Votes

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 Beginner ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

Thanks. I tried it, and it does rename all the files changing "Black" to "White" but only selects all and inverts the colors on the one file which I am viewing in the list of opened files, and it seems to do the "select all - Invert colors" twice on this one file.  All other open files only get the filename change, but not the actual color change of the shapes inside. I appreciate your help.

Votes

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 ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

Hi,

You can try below version

for (var i = app.documents.length - 1; i >= 0; i--) {
    var doc = app.documents[i];
    app.activeDocument = doc;
    var fileName = doc.fullName;
    app.executeMenuCommand('selectall')
    app.executeMenuCommand('Colors6')
    var saveOpts = new EPSSaveOptions();
    var _newFileName = fileName.fsName.replace('Black', 'White')
    doc.saveAs(File(_newFileName), saveOpts);
    app.executeMenuCommand('deselectall')
    doc.close( SaveOptions.DONOTSAVECHANGES);
}
Best regards

Votes

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 Beginner ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

That worked perfectly! Thank you so much!

Votes

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 Beginner ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

LATEST

Hi there. Thanks again for helping with this. We've just discovered an issue that has been causing us problems. Every time we run this script, it checks this box again when we go to save our next file. This causes an issue when brining the EPS files into Photoshop as it causes the #000 Black colors in the EPS to not be #000 Black in Photoshop (pure black). Is there some code you could add to this to make sure during the Save As process when renaming "Black" to "White" that this box remains unchecked? 

Votes

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 ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

It might be a good idea to loop backwards and close the respective active document after saving.

Votes

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