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

I need a script to run a specific action and save file as .jpg with SAME document name

Community Beginner ,
Apr 07, 2015 Apr 07, 2015

Copy link to clipboard

Copied

I have all my master PSD files saved like the following: mydocument_PSD.psd. I want it to run a custom sharpening action and then save the file as mydocument.jpg (note the "_PSD" portion needs to be removed).

I found this Photoshop-Export-PSD-script/Export-PSD.jsx at master · edwardloveall/Photoshop-Export-PSD-script · G... that gets me almost there but it's for a png and it's the straight document name and there is no action ran.

Any ideas?

TOPICS
Actions and scripting

Views

416

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

Enthusiast , Apr 07, 2015 Apr 07, 2015

Give this a try..

#target photoshop;  

 

main();  

function main(){  

if(!documents.length) return;  

try{  

    var path = activeDocument.path;  

    }catch(e){  

        alert("This document has not been saved");  

        return;  

        }  

if(activeDocument.name.toString().toLowerCase().search(/_psd\.psd$/) == -1){  

    alert("Filename is not in the correct format");  

    return;  

    }  

var fileName = activeDocument.name.toString().match(/[^_]*/);  

var savedState = a

...

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 07, 2015 Apr 07, 2015

Copy link to clipboard

Copied

Photoshop menu File>Scripts>Image Processor...

JJMack

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
Enthusiast ,
Apr 07, 2015 Apr 07, 2015

Copy link to clipboard

Copied

#target photoshop;

main();

function main(){

if(!documents.length) return;

try{

    var path = activeDocument.path;

    }catch(e){

        alert("This document has not been saved");

        return;

        }

if(activeDocument.name.toString().toLowerCase().search(/_psd\.psd$/) == -1){

    alert("Filename is not in the correct format");

    return;

    }

var fileName = activeDocument.name.toString().match(/[^_]*/);

var savedState = activeDocument.activeHistoryState;

//Amend with the correct action name and action set (case sensitive!)

doAction("ActionName","ActionSet");

//////////////////////////////////////////////////////////////////////

SaveJPEG(File(path + "/" + fileName + ".jpg"),8);

activeDocument.activeHistoryState = savedState;

};

function SaveJPEG(saveFile, jpegQuality){

jpgSaveOptions = new JPEGSaveOptions();

jpgSaveOptions.embedColorProfile = true;

jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

jpgSaveOptions.matte = MatteType.NONE;

jpgSaveOptions.quality = jpegQuality;

activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);

};

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 07, 2015 Apr 07, 2015

Copy link to clipboard

Copied

Philip, thanks SO MUCH. Unfortunately, I was having problems with it because the action I was using saves a large version of the file (original size), then creates a new document, shrinks it, and performs more actions and saves a small version of the file. So what I did was create two separate actions, "savelarge" and "savesmall" and tried to get the script you just wrote to do both one after another. So we start with mydocument_PSD.psd and the script saves them as "mydocument_large.jpg" and "mydocument_small.jpg". It seems to be working but I wanted to make sure I wasn't messing anything up.

Do you see anything below that looks incorrect? Again, thanks sooo much.

#target photoshop;

main();

function main(){

if(!documents.length) return;

try{

    var path = activeDocument.path;

    }catch(e){

        alert("This document has not been saved");

        return;

        }

if(activeDocument.name.toString().toLowerCase().search(/_psd\.psd$/) == -1){

    alert("Filename is not in the correct format");

    return;

    }

var fileName = activeDocument.name.toString().match(/[^_]*/);

var savedState = activeDocument.activeHistoryState;

//Amend with the correct action name and action set (case sensitive!)

doAction("savelarge","Action Set");

//////////////////////////////////////////////////////////////////////

SaveJPEG(File(path + "/" + fileName + "_large.jpg"),10);

activeDocument.activeHistoryState = savedState;

function SaveJPEG(saveFile, jpegQuality){

jpgSaveOptions = new JPEGSaveOptions();

jpgSaveOptions.embedColorProfile = true;

jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

jpgSaveOptions.matte = MatteType.NONE;

jpgSaveOptions.quality = jpegQuality; 

activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);

};

var fileName2 = activeDocument.name.toString().match(/[^_]*/);

var savedState2 = activeDocument.activeHistoryState;

doAction("savesmall","Action Set");

//////////////////////////////////////////////////////////////////////

SaveJPEG2(File(path + "/" + fileName2 + "_small.jpg"),10);

activeDocument.activeHistoryState = savedState2;

}; 

function SaveJPEG2(saveFile, jpegQuality){

jpgSaveOptions = new JPEGSaveOptions();

jpgSaveOptions.embedColorProfile = true;

jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

jpgSaveOptions.matte = MatteType.NONE;

jpgSaveOptions.quality = jpegQuality; 

activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);

};

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
Enthusiast ,
Apr 07, 2015 Apr 07, 2015

Copy link to clipboard

Copied

Give this a try..

#target photoshop;  

 

main();  

function main(){  

if(!documents.length) return;  

try{  

    var path = activeDocument.path;  

    }catch(e){  

        alert("This document has not been saved");  

        return;  

        }  

if(activeDocument.name.toString().toLowerCase().search(/_psd\.psd$/) == -1){  

    alert("Filename is not in the correct format");  

    return;  

    }  

var fileName = activeDocument.name.toString().match(/[^_]*/);  

var savedState = activeDocument.activeHistoryState;  

doAction("savelarge","Action Set");  

//////////////////////////////////////////////////////////////////////  

SaveJPEG(File(path + "/" + fileName + "_large.jpg"),10);  

activeDocument.activeHistoryState = savedState;   

savedState = activeDocument.activeHistoryState;  

doAction("savesmall","Action Set");  

//////////////////////////////////////////////////////////////////////  

SaveJPEG(File(path + "/" + fileName + "_small.jpg"),10); 

activeDocument.activeHistoryState = savedState;  

};   

function SaveJPEG(saveFile, jpegQuality){  

jpgSaveOptions = new JPEGSaveOptions();  

jpgSaveOptions.embedColorProfile = true;  

jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;  

jpgSaveOptions.matte = MatteType.NONE;  

jpgSaveOptions.quality = jpegQuality;   

activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);  

};

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 07, 2015 Apr 07, 2015

Copy link to clipboard

Copied

LATEST

BINGO!! You're the man. Thanks 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