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

save all open documents in psd

Advocate ,
Mar 21, 2020 Mar 21, 2020

save all open documents in psd
in the same path as the original files

 

and rename the source file from test.jpg to test.psd

a.png

TOPICS
Actions and scripting
7.6K
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

Mentor , Mar 22, 2020 Mar 22, 2020

try this:

for (var i=0; i<app.documents.length; i++) {
    var doc = app.activeDocument = app.documents[i],
    f = doc.fullName
    doc.saveAs (File(f.path + "/" + decodeURI(f.name).replace(/\.\S+$/, "") + ".psd"))
    f.remove()
}

* i think I understand what the geppettol66959005 needs

Translate
Adobe
Community Expert ,
Mar 21, 2020 Mar 21, 2020

You could try 

File > Scripts > Image Processor 

with »Save as PSD«. 

 

But as the psd-files are not the jpg-files renaming them does not seem to be an option. 

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
Advocate ,
Mar 21, 2020 Mar 21, 2020

c_pfaffenbichler
I need a clean script because I have to put it in a quick button.

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 Expert ,
Mar 21, 2020 Mar 21, 2020

Say what? 

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
Advocate ,
Mar 21, 2020 Mar 21, 2020

I have this
but it only works for jpg

i would like the same for psd.

 

var startDisplayDialogs = app.displayDialogs
app.displayDialogs = DialogModes.NO


if (app.documents.length > 0) {
   var theFirst = app.activeDocument;
   var theDocs = app.documents;

   jpgOpts = new JPEGSaveOptions( );
   jpgOpts.embedColorProfile = true;
   jpgOpts.formatOptions = FormatOptions.STANDARDBASELINE;
   jpgOpts.matte = MatteType.NONE;
   jpgOpts.quality = 12;

   for (var m = 0; m < theDocs.length; m++) {
     var theDoc = theDocs[m];
     var num = m + 1;
     app.activeDocument = theDoc;

     theDoc.saveAs((new File("~/Desktop/file_" + num)), jpgOpts, false, Extension.LOWERCASE); 
   };
   app.activeDocument = theFirst;
};

 

 

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 Expert ,
Mar 21, 2020 Mar 21, 2020
It seems to me that your original post did not describe what you want by a long shot. 
Anyway, this should save the files with numbers to the Destop. 
 
var startDisplayDialogs = app.displayDialogs
app.displayDialogs = DialogModes.NO
 
 
if (app.documents.length > 0) {
   var theFirst = app.activeDocument;
   var theDocs = app.documents;
 
// psd options;
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = true;
psdOpts.layers = true;
psdOpts.spotColors = true;
 
   for (var m = 0; m < theDocs.length; m++) {
     var theDoc = theDocs[m];
     var num = m + 1;
     app.activeDocument = theDoc;
     theDoc.saveAs((new File("~/Desktop/file_" + num + ".psd")), psdOpts, false, Extension.LOWERCASE);
   };
   app.activeDocument = theFirst;
};
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
Advocate ,
Mar 21, 2020 Mar 21, 2020

c_pfaffenbichler

The script is fine but the files are not saved in the original folder
in the same path as the original files

the files must keep the original name with the extension .psd

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 Expert ,
Mar 21, 2020 Mar 21, 2020

Then why did you say: »i would like the same for psd«? 

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 ,
Jul 28, 2021 Jul 28, 2021

Change theDocs.length to 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 ,
Jul 28, 2021 Jul 28, 2021

For me it worked.

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 ,
Jul 28, 2021 Jul 28, 2021
LATEST
for (var m = 0; m < 1; m++) {
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
Mentor ,
Mar 21, 2020 Mar 21, 2020

save all open documents in psd
in the same path as the original files

 

and rename the source file from test.jpg to test.psd

 

for (var i=0; i<app.documents.length; i++) {
    var f = app.documents[i].fullName, 
    p = f.path, 
    n = decodeURI(f.name).replace(/\.\S+$/, "")
    app.documents[i].saveAs (File(p + "/" + n + ".psd"))
    f.remove() // removes original file, delete this line if it is not necessary
}

 

* unsaved documents that do not have a disk path will cause an error. In this case, the c_pfaffenbichler code is more suitable

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 Expert ,
Mar 21, 2020 Mar 21, 2020

Only for addition

var aDoc = activeDocument;
try {
    var docPath = aDoc.path;
} catch (e) {
    alert("not saved before");
    // code for saving
    }
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
Mentor ,
Mar 21, 2020 Mar 21, 2020

... also document names may contain characters not supported by the current file system, there may be other errors while saving the file (read only or inaccessible folder), etc. - all this things needs to be processed...
I think that geppettol66959005 just does not need it.

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 ,
Mar 21, 2020 Mar 21, 2020

AM solution:

 

sTT = stringIDToTypeID; (ref = new ActionReference())
.putProperty(sTT('property'), fR = sTT('fileReference'))
ref.putEnumerated(sTT('document'), sTT('ordinal'),
sTT('targetEnum')), executeActionGet(ref).hasKey(fR)
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
Mentor ,
Mar 21, 2020 Mar 21, 2020

Great short code!

I was sure that if the necessary property not found, executeActionGet (ref) will cause an error...

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 Expert ,
Mar 21, 2020 Mar 21, 2020

Hi @Kukurykus,

nice code.

 

But i like the "normal" AM-coding much more.

var ref = new ActionReference ();
ref.putEnumerated (stringIDToTypeID ("document"), stringIDToTypeID ("ordinal"), stringIDToTypeID ("targetEnum"));
executeActionGet (ref).hasKey (stringIDToTypeID ("fileReference"));

 

There was a really long discussion in the old (Jive) Photoshop Scripting Forum.

https://community.adobe.com/#4917760

But this thread is archived (I think) and unfortunately is no longer available.

😞

 

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
Mentor ,
Mar 21, 2020 Mar 21, 2020

... in any case, it is better  faster to get a separate property than the whole desc object ... 

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 ,
Mar 21, 2020 Mar 21, 2020

What was that disscusion about?

 

btw like DmitryEgorov said you didn't use property at beginning that makes code much slower.

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 Expert ,
Mar 21, 2020 Mar 21, 2020

@Kukurykus wrote: "What was that disscusion about? …"

 

That was a very long and good discussion about: Was an image ever been saved before?

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
Advocate ,
Mar 21, 2020 Mar 21, 2020

guys many answers but no valid solution?

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 Expert ,
Mar 21, 2020 Mar 21, 2020

Why not?

All necessary components are available - just not all possible scenarios.

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
Advocate ,
Mar 21, 2020 Mar 21, 2020

then it is I who is incapable Because I haven't found the solution yet

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
Mentor ,
Mar 21, 2020 Mar 21, 2020

What is wrong with this code?

for (var i=0; i<app.documents.length; i++) {
    var f = app.documents[i].fullName, 
    p = f.path, 
    n = decodeURI(f.name).replace(/\.\S+$/, "")
    app.documents[i].saveAs (File(p + "/" + n + ".psd"))
    f.remove() // removes original file, delete this line if it is not necessary
}
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
Advocate ,
Mar 22, 2020 Mar 22, 2020

Dmitry

Your script doesn't save all open documents.

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