Highlighted

save all open documents in psd

Advocate ,
Mar 21, 2020

Copy link to clipboard

Copied

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

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

Topics

Actions and scripting

Views

1.3K

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

save all open documents in psd

Advocate ,
Mar 21, 2020

Copy link to clipboard

Copied

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

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

Topics

Actions and scripting

Views

1.3K

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

Copy link to clipboard

Copied

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. 

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
Reply
Loading...
Mar 21, 2020 1
Advocate ,
Mar 21, 2020

Copy link to clipboard

Copied

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

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
Reply
Loading...
Mar 21, 2020 0
LEGEND ,
Mar 21, 2020

Copy link to clipboard

Copied

Say what? 

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
Reply
Loading...
Mar 21, 2020 0
Advocate ,
Mar 21, 2020

Copy link to clipboard

Copied

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

 

 

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
Reply
Loading...
Mar 21, 2020 0
LEGEND ,
Mar 21, 2020

Copy link to clipboard

Copied

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

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
Reply
Loading...
Mar 21, 2020 1
Advocate ,
Mar 21, 2020

Copy link to clipboard

Copied

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

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
Reply
Loading...
Mar 21, 2020 0
LEGEND ,
Mar 21, 2020

Copy link to clipboard

Copied

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

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
Reply
Loading...
Mar 21, 2020 2
Enthusiast ,
Mar 21, 2020

Copy link to clipboard

Copied

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

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
Reply
Loading...
Mar 21, 2020 2
Most Valuable Participant ,
Mar 21, 2020

Copy link to clipboard

Copied

Only for addition

var aDoc = activeDocument;
try {
    var docPath = aDoc.path;
} catch (e) {
    alert("not saved before");
    // code for saving
    }

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
Reply
Loading...
Mar 21, 2020 2
Enthusiast ,
Mar 21, 2020

Copy link to clipboard

Copied

... 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.

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
Reply
Loading...
Mar 21, 2020 1
Adobe Community Professional ,
Mar 21, 2020

Copy link to clipboard

Copied

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)

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
Reply
Loading...
Mar 21, 2020 3
Enthusiast ,
Mar 21, 2020

Copy link to clipboard

Copied

Great short code!

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

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
Reply
Loading...
Mar 21, 2020 2
Most Valuable Participant ,
Mar 21, 2020

Copy link to clipboard

Copied

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.

😞

 

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
Reply
Loading...
Mar 21, 2020 2
Enthusiast ,
Mar 21, 2020

Copy link to clipboard

Copied

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

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
Reply
Loading...
Mar 21, 2020 1
Adobe Community Professional ,
Mar 21, 2020

Copy link to clipboard

Copied

What was that disscusion about?

 

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

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
Reply
Loading...
Mar 21, 2020 0
Most Valuable Participant ,
Mar 21, 2020

Copy link to clipboard

Copied

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

 

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

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
Reply
Loading...
Mar 21, 2020 1
Advocate ,
Mar 21, 2020

Copy link to clipboard

Copied

guys many answers but no valid solution?

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
Reply
Loading...
Mar 21, 2020 0
Most Valuable Participant ,
Mar 21, 2020

Copy link to clipboard

Copied

Why not?

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

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
Reply
Loading...
Mar 21, 2020 1
Advocate ,
Mar 21, 2020

Copy link to clipboard

Copied

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

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
Reply
Loading...
Mar 21, 2020 0
Enthusiast ,
Mar 21, 2020

Copy link to clipboard

Copied

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
}

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
Reply
Loading...
Mar 21, 2020 1
Advocate ,
Mar 22, 2020

Copy link to clipboard

Copied

Dmitry

Your script doesn't save all open documents.

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
Reply
Loading...
Mar 22, 2020 0
LEGEND ,
Mar 22, 2020

Copy link to clipboard

Copied

Cssn you provide meaningful information for once? 

Please post screenshots to clarify what goes awry. 

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
Reply
Loading...
Mar 22, 2020 0
Adobe Community Professional ,
Mar 22, 2020

Copy link to clipboard

Copied

Loll, liking stopped to work for me, so I had to like you by saying it 🙂

 

Edit: it worked but with much delay.

 

Ps. I found another bad thing. During posting I could not go to next line (pressing Enter after smile face), so I removed it, pressed enter, added more text and in the highest line I used smile again 😕

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
Reply
Loading...
Mar 22, 2020 1
Advocate ,
Mar 22, 2020

Copy link to clipboard

Copied

c_pfaffenbichler

the problem is this when I use this script

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

 

It happens to me that the name of the document changes
these are the original names

1.png

 

after the script this happens
change the original name to (file_ ")

2.png

 

This is not good for me
I wish the original name would remain.

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
Reply
Loading...
Mar 22, 2020 0
LEGEND ,
Mar 22, 2020

Copy link to clipboard

Copied

That that code did not what you wanted has been established. 

 

What was the problem with the code DmitryEgorov had provided? 

 

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
Reply
Loading...
Mar 22, 2020 0
Enthusiast ,
Mar 22, 2020

Copy link to clipboard

Copied

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

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
Reply
Loading...
Mar 22, 2020 1
Advocate ,
Mar 22, 2020

Copy link to clipboard

Copied

The problem is this before using the script the names are these

1.png

 

After I use the script it happens that it changes the name to so

2.png

 

This is not good for me
I wish the original name would remain.

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
Reply
Loading...
Mar 22, 2020 0
LEGEND ,
Mar 22, 2020

Copy link to clipboard

Copied

I tested the code from DmitryEgorov’s last post and from this 

Screenshot 2020-03-22 at 13.12.05.png

I get this 

Screenshot 2020-03-22 at 13.12.50.png

 

There should’t be an open jpg after running the Script, so just to make sure: Did you run the last version? 

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
Reply
Loading...
Mar 22, 2020 0
Advocate ,
Mar 22, 2020

Copy link to clipboard

Copied

I have run the latest version
now try to do this the files call them differently type

mano.jpg
piede.jpg
see what happens

another thing instead of opening 2 files open 3
and let me know what comes out

thank you for your time

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
Reply
Loading...
Mar 22, 2020 0
LEGEND ,
Mar 22, 2020

Copy link to clipboard

Copied

In the previous post I already showed what happend for 3 open files for me, this time for two with the names »mano.jpg« and »piede.jpg«: 

Screenshot 2020-03-22 at 13.29.44.pngScreenshot 2020-03-22 at 13.30.03.png

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
Reply
Loading...
Mar 22, 2020 0
LEGEND ,
Mar 22, 2020

Copy link to clipboard

Copied

The names seem to be honored, see screenshots from before and after running the Script: 

Screenshot 2020-03-22 at 13.29.44.pngScreenshot 2020-03-22 at 13.30.03.png

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
Reply
Loading...
Mar 22, 2020 0
LEGEND ,
Mar 22, 2020

Copy link to clipboard

Copied

Screenshot 2020-03-22 at 13.30.03.pngScreenshot 2020-03-22 at 13.29.44.png

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
Reply
Loading...
Mar 22, 2020 0
LEGEND ,
Mar 22, 2020

Copy link to clipboard

Copied

Seems I can’t post screenshots on this Forum at current, but I tried with the names »mano.jpg« and »piede.jpg« and it worked as expected. 

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
Reply
Loading...
Mar 22, 2020 0
Adobe Community Professional ,
Sep 08, 2020

Copy link to clipboard

Copied

You can post, but with delay 😉

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
Reply
Loading...
Sep 08, 2020 0
LEGEND ,
Mar 22, 2020

Copy link to clipboard

Copied

I tried with the names »mano.jpg« and »piede.jpg« and it worked as expected. 

Screenshot 2020-03-22 at 13.29.44.pngScreenshot 2020-03-22 at 13.30.03.png

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
Reply
Loading...
Mar 22, 2020 0
Advocate ,
Mar 22, 2020

Copy link to clipboard

Copied

c_pfaffenbichler 

Sorry I'm a goat
I made a trivial mistake.

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
Reply
Loading...
Mar 22, 2020 1