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

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

Community Beginner ,
Jun 14, 2021 Jun 14, 2021

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
4.1K
Translate
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

LEGEND , Jun 14, 2021 Jun 14, 2021

 

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

 

Translate
Community Expert ,
Jun 14, 2021 Jun 14, 2021

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

 

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

 

Translate
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

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

Translate
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 ,
Aug 24, 2021 Aug 24, 2021

Is this a script? if yes, how can I use it? can I use it when I run an Action?

Translate
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
LEGEND ,
Aug 24, 2021 Aug 24, 2021

Save it as saving.jsx in 'Presets / Scripts' folder of your Photoshop. Then relaunch Ps and instead of your saveAs action item use this script. To do it select in your action where you want it to be placed, then from expandable menu of Action panel choose 'Insert Menu Item' and from 'File / Scripts' choose the 'saving' item.

Translate
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 ,
Aug 24, 2021 Aug 24, 2021

It says: error 8800: geral error. die function is not for this version of Photoshop.

😕

Translate
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
LEGEND ,
Aug 24, 2021 Aug 24, 2021

Did you use such code:

 

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

 

Describe step by step what you're doing, so I can know if you did something wrong.

Translate
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 ,
Aug 24, 2021 Aug 24, 2021

it works just fine now, thank you. now I'm just trying to change the save path and save it on a server which I use.
can you maybe help me do that?
normally I use finder => go to =>connect to server=> then i write this path and then i can accses the server.

for example: smb://vol.local/jpgFiles

but when I past this path to your code, it won't run anymore:
(ad = activeDocument).saveAs(File('smb://vol.local/' + ad.name), new JPEGSaveOptions, true)

Translate
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
LEGEND ,
Aug 24, 2021 Aug 24, 2021

Save manually any file in that loaction, then open it in Photoshop. Finally run this script:

 

 

alert(decodeURI(activeDocument.path))

 

 

It's going to alert a correct path of that file. Use it, also make alert screenshot to paste it here.

 

Ps. I was notified of marking the correct solution in other thread, but when visiting that it's not marked. Have you unmarked it meantime for some reason or that happened itself?

Translate
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 ,
Aug 24, 2021 Aug 24, 2021

YOU ARE A SAVIOUR.

THANK YOU

Translate
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 ,
Aug 24, 2021 Aug 24, 2021

I just found out that if I save using this script, the quality is reduces the quality of JPEG file to 3.

How can I increase the quality to 12?

Translate
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
LEGEND ,
Aug 24, 2021 Aug 24, 2021

Add at top:

 

(jpg = new JPEGSaveOptions).quality = 12;

 

while 'saving options' change to:

 

jpg

 

Translate
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 ,
Aug 24, 2021 Aug 24, 2021

Thank you. I did this and it works 😉

(ad = activeDocument).saveAs(File('/Mark/jpj/' + ad.name), new JPEGSaveOptions(JPEGSaveOptions.quality = 12), true)

Translate
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
LEGEND ,
Aug 24, 2021 Aug 24, 2021

Very interesting. I didn't know it can be done this way. Did you find it by mistake?

Translate
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 ,
Aug 24, 2021 Aug 24, 2021

I know a little bit JavaScript and just tried and it worked 😉

it would be nice if you help me find a script to change the position of the number in the filename.

for ex: fileName_001.jpg to => 001_fileName.jpg

shoule I create another post for this quistion?

 

Translate
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
LEGEND ,
Aug 24, 2021 Aug 24, 2021

If open document has already similar name you want to change to other, then use:

 

activeDocument.name.replace(/(.*)(_)(\d{3})/, '$3$2$1')

 

Translate
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 ,
Aug 24, 2021 Aug 24, 2021

the scripts runs without any error, but nothing changes. I mean the name wont change. 😕

Translate
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
LEGEND ,
Aug 25, 2021 Aug 25, 2021

Did you put it instead of aD.name?

Translate
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 ,
Aug 25, 2021 Aug 25, 2021

I created a new script file with only this script:

activeDocument.name.replace(/(.*)(_)(\d{3})/, '$3$2$1')

Translate
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
LEGEND ,
Aug 25, 2021 Aug 25, 2021

To apply it you must use it in previous script as said. It works while saving the file.

Translate
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 ,
Aug 25, 2021 Aug 25, 2021

wow... so cool 😄

Translate
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 ,
Aug 25, 2021 Aug 25, 2021

Is this possible to use somehow this script (place the numbers in the file name) when I export document for web as png?

Translate
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
LEGEND ,
Aug 25, 2021 Aug 25, 2021
LATEST

There are many Save for Web threads showing how to export images by scripting. Find them.

Translate
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 ,
Aug 24, 2021 Aug 24, 2021

Thank you.

I changed both "aD"s to ad and it works great now. 🙂

could you tell me how to save as JPG, not PNG?

Translate
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