Skip to main content
Participant
April 7, 2015
Answered

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

  • April 7, 2015
  • 2 replies
  • 567 views

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 · GitHub 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?

This topic has been closed for replies.
Correct answer I have gone

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);  

};

2 replies

Inspiring
April 7, 2015

#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);

};

bradatxAuthor
Participant
April 7, 2015

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);

};

I have goneCorrect answer
Inspiring
April 7, 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 = 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);  

};

JJMack
Community Expert
Community Expert
April 7, 2015

Photoshop menu File>Scripts>Image Processor...

JJMack