Action or Script to automate saving PNGs without appending "copy" to the filename.

Community Beginner ,
Jun 14, 2021 Jun 14, 2021

Copy link to clipboard

Copied

I want to create an action to save PNGs to a folder on my desktop without the suffix "copy" being added. I know that with the new release of Photoshop 22.4.2, a check box in prefferences has been added to create the abilitty to ommit "copy" from being added ("Do not append "copy" to filename when saving" in Prefferences/File Handling). It works great when I am just saving out one png file. However, I can't get it to work in an action without brining up a dialogue box. If I have to hit the enter button for each file, the time I would have saved from the action is lost.

 

Adobe, is there a way to write an action without the dialogue box?

 

Has anyone writen a script I could run instead of an action in the meantime? Again, I just want to save a png from a psd to a folder called "PNG" on my desktop without "copy" being added to the end of the name.

TOPICS
Actions and scripting, Bug, Feature request, How to, Import and export, Mac

Views

678

Likes

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

Adobe Community Professional , Jun 14, 2021 Jun 14, 2021
(aD = activeDocument).saveAs(File('~/desktop/PNG/' + aD.name), new PNGSaveOptions, true)

Likes

Translate

Translate
Adobe Community Professional ,
Jun 14, 2021 Jun 14, 2021

Copy link to clipboard

Copied

You could modify this script to not check if the current document has been saved a save a png file onto the current document folder.   Just Set the path to your desktop "~/Desktop/PNG/" plus the document name and save the png.  However, on a Mac Apple MacOS 10.1.5+ may add a copy

 

 

try {
	var tmp = app.activeDocument.fullName.name;
    ftype = decodeURI(tmp.substring(tmp.lastIndexOf("."),)).toLowerCase();
	if (ftype==".nef"  || ftype==".cr3" || ftype==".cr2" || ftype==".crw" || ftype==".dcs" || ftype==".raf" || ftype==".arw" || ftype==".orf") { throw "error1"; }
	fname = decodeURI(tmp.substring(0, tmp.lastIndexOf(".")));
	SaveAsPNG(app.activeDocument.path + "/" + fname, "PNG24", false, true);

}
catch(e) {alert("Document has not been save yet")}

function SaveAsPNG(saveFile, PNGtype, Interlace, Transparency) {
	//alert(saveFile + "\n" + PNGtype + "\n" + Interlace + "\n" +  Transparency)
	if (PNGtype=="PNG8") {		
		var id5 = charIDToTypeID( "Expr" );
		var desc3 = new ActionDescriptor();
		var id6 = charIDToTypeID( "Usng" );
		var desc4 = new ActionDescriptor();
		var id7 = charIDToTypeID( "Op  " );
		var id8 = charIDToTypeID( "SWOp" );
		var id9 = charIDToTypeID( "OpSa" );
		desc4.putEnumerated( id7, id8, id9 );
		var id10 = charIDToTypeID( "Fmt " );
		var id11 = charIDToTypeID( "IRFm" );
		var id12 = charIDToTypeID( "PNG8" );
		desc4.putEnumerated( id10, id11, id12 );
		var id13 = charIDToTypeID( "Intr" ); //Interlaced
		desc4.putBoolean( id13, Interlace );
		var id14 = charIDToTypeID( "RedA" );
		var id15 = charIDToTypeID( "IRRd" );
		var id16 = charIDToTypeID( "Prcp" ); //Algorithm
		desc4.putEnumerated( id14, id15, id16 );
		var id17 = charIDToTypeID( "RChT" );
		desc4.putBoolean( id17, false );
		var id18 = charIDToTypeID( "RChV" );
		desc4.putBoolean( id18, false );
		var id19 = charIDToTypeID( "AuRd" );
		desc4.putBoolean( id19, false );
		var id20 = charIDToTypeID( "NCol" ); //NO. Of Colors
		desc4.putInteger( id20, 256 );
		var id21 = charIDToTypeID( "Dthr" ); //Dither
		var id22 = charIDToTypeID( "IRDt" );
		var id23 = charIDToTypeID( "Dfsn" ); //Dither type
		desc4.putEnumerated( id21, id22, id23 );
		var id24 = charIDToTypeID( "DthA" );
		desc4.putInteger( id24, 100 );
		var id25 = charIDToTypeID( "DChS" );
		desc4.putInteger( id25, 0 );
		var id26 = charIDToTypeID( "DCUI" );
		desc4.putInteger( id26, 0 );
		var id27 = charIDToTypeID( "DChT" );
		desc4.putBoolean( id27, false );
		var id28 = charIDToTypeID( "DChV" );
		desc4.putBoolean( id28, false );
		var id29 = charIDToTypeID( "WebS" );
		desc4.putInteger( id29, 0 );
		var id30 = charIDToTypeID( "TDth" ); //transparency dither
		var id31 = charIDToTypeID( "IRDt" );
		var id32 = charIDToTypeID( "None" );
		desc4.putEnumerated( id30, id31, id32 );
		var id33 = charIDToTypeID( "TDtA" );
		desc4.putInteger( id33, 100 );
		var id34 = charIDToTypeID( "Trns" ); //Transparency
		desc4.putBoolean( id34, Transparency );
		var id35 = charIDToTypeID( "Mtt " );
		desc4.putBoolean( id35, true );		 //matte
		var id36 = charIDToTypeID( "MttR" ); //matte color
		desc4.putInteger( id36, 255 );
		var id37 = charIDToTypeID( "MttG" );
		desc4.putInteger( id37, 255 );
		var id38 = charIDToTypeID( "MttB" );
		desc4.putInteger( id38, 255 );
		var id39 = charIDToTypeID( "SHTM" );
		desc4.putBoolean( id39, false );
		var id40 = charIDToTypeID( "SImg" );
		desc4.putBoolean( id40, true );
		var id41 = charIDToTypeID( "SSSO" );
		desc4.putBoolean( id41, false );
		var id42 = charIDToTypeID( "SSLt" );
		var list1 = new ActionList();
		desc4.putList( id42, list1 );
		var id43 = charIDToTypeID( "DIDr" );
		desc4.putBoolean( id43, false );
		var id44 = charIDToTypeID( "In  " );
		desc4.putPath( id44, new File(saveFile + ".png") );
		var id45 = stringIDToTypeID( "SaveForWeb" );
		desc3.putObject( id6, id45, desc4 );
		executeAction( id5, desc3, DialogModes.NO );
    }
	else { //png 24
		var id6 = charIDToTypeID( "Expr" );
		var desc3 = new ActionDescriptor();
		var id7 = charIDToTypeID( "Usng" );
		var desc4 = new ActionDescriptor();
		var id8 = charIDToTypeID( "Op  " );
		var id9 = charIDToTypeID( "SWOp" );
		var id10 = charIDToTypeID( "OpSa" );
        desc4.putEnumerated( id8, id9, id10 );
		var id11 = charIDToTypeID( "Fmt " );
		var id12 = charIDToTypeID( "IRFm" );
		var id13 = charIDToTypeID( "PN24" );
		desc4.putEnumerated( id11, id12, id13 );
		var id14 = charIDToTypeID( "Intr" );
		desc4.putBoolean( id14, Interlace );
		var id15 = charIDToTypeID( "Trns" );
		desc4.putBoolean( id15, Transparency );
		var id16 = charIDToTypeID( "Mtt " );
		desc4.putBoolean( id16, true );
		var id17 = charIDToTypeID( "MttR" );
		desc4.putInteger( id17, 255 );
		var id18 = charIDToTypeID( "MttG" );
		desc4.putInteger( id18, 255 );
		var id19 = charIDToTypeID( "MttB" );
		desc4.putInteger( id19, 255 );
		var id20 = charIDToTypeID( "SHTM" );
		desc4.putBoolean( id20, false );
		var id21 = charIDToTypeID( "SImg" );
		desc4.putBoolean( id21, true );
		var id22 = charIDToTypeID( "SSSO" );
		desc4.putBoolean( id22, false );
		var id23 = charIDToTypeID( "SSLt" );
		var list1 = new ActionList();
		desc4.putList( id23, list1 );
		var id24 = charIDToTypeID( "DIDr" );
		desc4.putBoolean( id24, false );
		var id25 = charIDToTypeID( "In  " );
		desc4.putPath( id25, new File( saveFile + ".png") );
		var id26 = stringIDToTypeID( "SaveForWeb" );
		desc3.putObject( id7, id26, desc4 );
		executeAction( id6, desc3, DialogModes.NO );
	}
}

 

 

 

JJMack

Likes

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
Adobe Community Professional ,
Jun 14, 2021 Jun 14, 2021

Copy link to clipboard

Copied

 

(aD = activeDocument).saveAs(File('~/desktop/PNG/' + aD.name), new PNGSaveOptions, true)

 

Likes

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 ,
Jun 15, 2021 Jun 15, 2021

Copy link to clipboard

Copied

AMAZING! Works perfectly, and is very clean. This will save me tons of time. Thank you very much!

Likes

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
Participant ,
Jun 14, 2021 Jun 14, 2021

Copy link to clipboard

Copied

This should do it...

 

 

#target photoshop;

function SavePng(Folder) {

    /* FileToSave = 
     * the Folder parameter
     * + the name of the document without extension
     * + png
     * 
     * This will break if there is no "." in the document's name (ie: if the document was not saved beforehand)
     */
    var FileToSave = new File(Folder+app.activeDocument.name.match(/(.*)\.[^\.]+$/)[1]+".png"); 

    SaveOptions = new PNGSaveOptions();
    SaveOptions.interlaced = true; 
    activeDocument.saveAs(FileToSave, SaveOptions, true, Extension.LOWERCASE);
}

/*Call the function using the folder where you want to save your png files, replace YOURUSERNAME with your user name. ;-)*/
SavePng("C:/Users/YOURUSERNAME/Desktop/PNG/");

 

 

edit: use the one from Kukurykus, it's a lot better.

Likes

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 ,
Jun 15, 2021 Jun 15, 2021

Copy link to clipboard

Copied

Thank you so much for putting time into helping out on this! I really appriciate it!

Likes

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
Adobe Community Professional ,
Jun 15, 2021 Jun 15, 2021

Copy link to clipboard

Copied

When I think of PNG file format I think of Apple,  Web Browser format, Supports Transparency and Photoshop Export save for web has more png options then  Photoshop "Save As" and Photoshop DOM Scripting PNGSaveOptions.  The ScriptListener Action Manager Code for both PNG8 and PMG24 are huge and unreadable with my knowledge of Acrion Manager code.  I also notices several of the Photoshop Scripts Adobe install with Photoshop support saving PNG8 and PNG24  files  using Action Manager Code where the scripts save the other Images file  using Scripting DOM code.   The Action Manger code used for PNG8 and PNG24 is not as many lines as the Scriptlistener records for Save for Web so I reused Adobe action manger code in my script.  In front of Adobe's Action Manager code for save for web Adobe has a ScriptUI Dialog the user uses to set some of the PNG8 and PNG24 save options.  My script has no dialog the settings must be passed to the SaveAsPNG function Though I saw embed ICC profile and a Trim check boxes in Adobe Dialog  for png8 and png24 I did not see them used  in Adobe Saved for web action manager code.    So my function SaveAsPNG has just four parms (File, PNG8|PNG24, Interlace, Transparency). I believe the DOM Doc.saveAs png is a PNG24 filetype.

JJMack

Likes

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 ,
Jun 15, 2021 Jun 15, 2021

Copy link to clipboard

Copied

LATEST

Thanks for putting time into your respnses JJMack. It's appriciated!

Likes

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