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
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
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.
Copy link to clipboard
Copied
c_pfaffenbichler
I need a clean script because I have to put it in a quick button.
Copy link to clipboard
Copied
Say what?
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;
};
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Then why did you say: »i would like the same for psd«?
Copy link to clipboard
Copied
Change theDocs.length to 1.
Copy link to clipboard
Copied
For me it worked.
Copy link to clipboard
Copied
for (var m = 0; m < 1; m++) {
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
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
}
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.
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)
Copy link to clipboard
Copied
Great short code!
I was sure that if the necessary property not found, executeActionGet (ref) will cause an error...
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.
😞
Copy link to clipboard
Copied
... in any case, it is better faster to get a separate property than the whole desc object ...
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.
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?
Copy link to clipboard
Copied
guys many answers but no valid solution?
Copy link to clipboard
Copied
Why not?
All necessary components are available - just not all possible scenarios.
Copy link to clipboard
Copied
then it is I who is incapable Because I haven't found the solution yet
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
}
Copy link to clipboard
Copied
Dmitry
Your script doesn't save all open documents.