Copy link to clipboard
Copied
Hy all,
this is the situation:
I have got a psd file. I want this file to be saved automatically as Documentname1.png while it originally is Documentname.psd.
The script doesn't have to ask what number i want to add, i can find that in the script and change that myself.
It also have to save the file in another folder than where the Documentname.psd is saved.
Could anyone creat a script for this action? I don't have any experience at scripting at all.
Tnx!
this folder is always the same, say that it is: C:\Documents and Settings\png
I think you meant your 'My Documents' folder, so here is a new version:
if (app.documents.length > 0) {
var myDoc = app.activeDocument;
var myDocName = myDoc.name;
if (myDocName.lastIndexOf("psd") > 0) {
var myNewFolder = new Folder(Folder.myDocuments.fsName + "/png");
if (!myNewFolder.exists) myNewFolder.create();
var myNewName = myDocName.replace(/.psd$/, "1.png");
var myNewFile = n
Copy link to clipboard
Copied
if (app.documents.length > 0) {
var myDoc = app.activeDocument;
var myDocFullName = myDoc.fullName.fsName;
if (myDoc.name.lastIndexOf('psd') > 0) {
var myNewPath = myDocFullName.replace( /.psd$/, '1.png' );
var myNewFile = new File(myNewPath);
myDoc.saveAs(myNewFile, SaveDocumentType.PNG, true, Extension.LOWERCASE);
}
else {
alert("The current document is not PSD-file.");
}
}
else {
alert("Please open a document and try again.");
}
Copy link to clipboard
Copied
how can i change the fact that the new png is saved at the same place as the original psd file??
But the script works great, only this little thing.
I think your first script is easier.
<offtopic> btw how did you learn javascript? I also want to learn it, so what is a good tutorial and where can you find all the names etc?? </offtopic>
Copy link to clipboard
Copied
Do you want the script to offer you to choose a folder for dng-files, or is this folder always the same – e.g. "Desktop/DNG files"?
Copy link to clipboard
Copied
this folder is always the same, say that it is: C:\Documents and Settings\png
Btw this does have to be changable in the script (so i can make 3 version of the script for 3 different folders).
Copy link to clipboard
Copied
this folder is always the same, say that it is: C:\Documents and Settings\png
I think you meant your 'My Documents' folder, so here is a new version:
if (app.documents.length > 0) {
var myDoc = app.activeDocument;
var myDocName = myDoc.name;
if (myDocName.lastIndexOf("psd") > 0) {
var myNewFolder = new Folder(Folder.myDocuments.fsName + "/png");
if (!myNewFolder.exists) myNewFolder.create();
var myNewName = myDocName.replace(/.psd$/, "1.png");
var myNewFile = new File(myNewFolder.fsName + "/" + myNewName);
myDoc.saveAs(myNewFile, SaveDocumentType.PNG, true, Extension.LOWERCASE);
}
else {
alert("The current document is not PSD-file.");
}
}
else {
alert("Please open a document and try again.");
}
You can change Folder.myDocuments.fsName to whatever path you want:
e.g. "~/Desktop" or "/c/images"
Copy link to clipboard
Copied
so if i want the file to be saved in the folder C:\Documents\images\png then I should put C/Documents/images/png in stead of the Folder.myDocuments.fsName thing?
i can't test it right now, but it is definetly looking good!
Copy link to clipboard
Copied
var myNewFolder = new Folder("/C/Documents/images/png");
Copy link to clipboard
Copied
You are a genius!!! Thanks a lot!
One little question? Is it possible to have a script, which asks you what name you want to save it, but in which the location is already determined.
I mean: normally when you save something in PS, and afterwards you save something else, you start there when you want to save something new. If it's possible to write a script which asks you what name you want to save the psd file, and this script saves it a place you already determined, then the other script can be done afterwards to make it save in various folders.
I hope you understand my story, but if this isn't possible, i'm already extremely happy with this script!
Copy link to clipboard
Copied
Is it possible to have a script, which asks you what name you want to save it, but in which the location is already determined.
certainly
I hope you understand my story...
Not quite. Do you want this script to show a dialog at start, and then resave the active (psd) document to the predefined location, using a new name that you typed in the dialog, and finally, save a png-copy of the file to the same location?
Copy link to clipboard
Copied
actually it's all about this sentence. This script is the first script to start with. I ask: "what's the name you want to save the file?" I give the name, and the script saves the file at a determined location as a psd (call the location /c/Documents/png for example).
This is what it's all about. This is the script to start with, so the file isn't already saved as a psd, this is the script which will take care of that. When this script is finished, i can run the script you made a few post ago (which works perfectly ) to save the psd file to a png file, so this one doesn't have to be included in this script, i just use the previous one.
it's all about the underlined sentences, the other sentences are just explenation.
Copy link to clipboard
Copied
if (app.documents.length > 0) {
var myDoc = app.activeDocument;
var myDocName = myDoc.name;
var myFolder = new Folder('~/Desktop/psd'); // change location to your own folder
if (!myFolder.exists) myFolder.create();
var myDialog = new Window('dialog', 'Save file as PSD');
myDialog.size = {width:300, height:90};
var myEditText = myDialog.add('edittext');
myEditText.preferredSize = {width:200, height:20};
var myNewName = myEditText.text;
var myGroup = myDialog.add('group');
myGroup.orientation = 'row';
var myOkBtn = myGroup.add('button', undefined, 'Resave', {name:'ok'});
var myCancelBtn = myGroup.add('button', undefined, 'Cancel', {name:'cancel'});
if (myDialog.show() == 1) {
var myNewName = myEditText.text;
if (myNewName != "") {
myNewName += '.psd';
var myNewFile = new File(myFolder.fsName + "/" + myNewName);
myDoc.saveAs(myNewFile, SaveDocumentType.PHOTOSHOP, true, Extension.LOWERCASE);
}
}
}
else {
alert('Please open a document and try again.');
}
I am on Mac right now, so I can't test it on PC.
Copy link to clipboard
Copied
This one is working with 1 file, so when i have got a file, run the script, enter the name, and voila, it's saved.
The problem is: when i include this one in my action, i do can give it a name, but afterwards it goes wrong.
Cause the script which you made before this one, doesn't work anymore by then. It gives an error like: Script error: the current document isn't a psd file.
I'll try to describe what kind of an action i have:
- i have got a picture which i'm gonna change with various actions.
- after i've done that, i save the picture to a psd file (i didn't save the picture earlier in the process, this is the first save!).
- therefor i need your latest script.
- after that's done, the document is saved as a psd file, and i directly run the other script you made to save this file at different locations and with different additions. This is now all going automatically, which is fantastic, cause the name which the images are going to have, was already given by saving the psd file.
I hope this describes my process a bit better, and helps you to get this one out
Copy link to clipboard
Copied
if (app.documents.length > 0) {
var myDoc = app.activeDocument;
var myDocName = myDoc.name;
var myFolder = new Folder('~/Desktop/psd'); // change location to your own folder
if (!myFolder.exists) myFolder.create();
var myDialog = new Window('dialog', 'Save file as PSD');
myDialog.size = {width:300, height:90};
var myEditText = myDialog.add('edittext');
myEditText.preferredSize = {width:200, height:20};
var myNewName = myEditText.text;
var myGroup = myDialog.add('group');
myGroup.orientation = 'row';
var myOkBtn = myGroup.add('button', undefined, 'Save', {name:'ok'});
var myCancelBtn = myGroup.add('button', undefined, 'Cancel', {name:'cancel'});
if (myDialog.show() == 1) {
var myNewName = myEditText.text;
if (myNewName != "") {
myNewName += '.psd';
var myNewFile = new File(myFolder.fsName + "/" + myNewName);
var id51 = charIDToTypeID( "save" );
var desc8 = new ActionDescriptor();
var id52 = charIDToTypeID( "As " );
var desc9 = new ActionDescriptor();
var id53 = stringIDToTypeID( "maximizeCompatibility" );
desc9.putBoolean( id53, true );
var id54 = charIDToTypeID( "Pht3" );
desc8.putObject( id52, id54, desc9 );
var id55 = charIDToTypeID( "In " );
desc8.putPath( id55, new File( myNewFile ) );
var id56 = charIDToTypeID( "LwCs" );
desc8.putBoolean( id56, true );
executeAction( id51, desc8, DialogModes.NO );
}
}
}
else {
alert('Please open a document and try again.');
}
Copy link to clipboard
Copied
Is it also possible to have a script which deletes a file??
I mean, in the beginning i create a script which saves a psd file, but actually i don't need that file after the process anymore.
So could it be possible to run a script after the action, which deletes this file?? Call the folder in which the file is C:\Documents\Psd or something.
Is it possible to make a script for this one??
Greetz
Copy link to clipboard
Copied
Sure. Do you want delete the psd-file in the script that saves a png-file? Or do you want to do this in a separate, 3rd script?
Copy link to clipboard
Copied
I would rather like it to be a 3rd script, so that the other scripts which are between these 1st and 3rd script, can run on the name of the psd file.
It would be great!
Copy link to clipboard
Copied
Ok. I'll make it, but not tonight – I'm finishing the current issue of our magazine.
Copy link to clipboard
Copied
ok, cool!
I'll see it comming
btw, what does i have to change on the save as psd document, to let it save as a png??
Copy link to clipboard
Copied
Hi,
I combined all the three scripts into one: it creates a floating panel with three buttons in Photoshop:
Save PSD – saves the active file in psd format to 'psd' folder on the desktop (if the folder doesn't exist, it will be created).
Save PNG – if the active files is in psd format, saves a copy in in png format to 'png' folder on the desktop (if the folder doesn't exist, it will be created).
Delete – deletes the last opened psd-file.
You can change the locations of the folders to what you need and change alignment of the buttons in the panel – read the comments.
Question: If you press ‘Delete’ button, but the document (last saved psd-file) is open in PS, what do you want to happen?
1. An alert appears "Can't delete…"
2. Close it silently and delete.
3. Same as 2, but ask confirmation
The script has grown too big to post it here, so download it from my site:
http://www.kasyan.ho.com.ua/save_psd_png_delete.html
Kasyan
Copy link to clipboard
Copied
It's really looking cool! but the thing is, this is all meant for an action, to do all the things a lot quicker.
So when i now have to press the right thing every time, isn't as handy as a script which does it automatical.
So i have got a little question: could you also create a seperate delete script, cause when i try to cut i out of the big script, and run it, it gives the error: undifined is not an object :S and to answer your question: if i use the delete script, i want the file to be closed and deleted (no conformation).
And could you also make something that when the save as png script runs, that when the new name already excists, the script will use (1).png in stead of .png??
Thanks a lot!
Copy link to clipboard
Copied
Ok, I’ll set myself to it tomorrow. it's easier to pull down than to build.
And could you also make something that when the save as png script runs, that when the new name already excists, the script will use (1).png in stead of .png
The first time you save it as png it will have the same base name as psd-file, the next time “1” will be appended to the end of the file name and every subsequent saving the number will be increment by 1:
e.g.
somefile.png
somefile1.png
somefile2.png
…
Right?
Copy link to clipboard
Copied
tnx a lot!! You are my hero in every case
The first time you save it as png it will have the same base name as psd-file, the next time “1” will be appended to the end of the file name and every subsequent saving the number will be increment by 1:
e.g.
somefile.png
somefile1.png
somefile2.png
…
Right?
No, i mean: The file always saves as the base name (from the psd-file). But when it saves it takes a look: does this name already excists?? If so it adds (1) behind the name, if not it just saves as the base name. And if (1) also excists, save it with (2) behind the name. (just until (3) much more it isn't going to be).
Thanks in advance!
Copy link to clipboard
Copied
I made three separate scripts, as you asked. And made the cursor to appear blinking in the text field, so it is ready for typing right after the dialog appears (save psd script).
Here is the link for download:
Copy link to clipboard
Copied
It's working PERFECTLY!!!!
Thanks a lot, i didn't face any problems yet, but if so, i know where to find my rescueing angle
Thanks for everything, this is really going to save me tons of time!
I don't know how to thank you more, but you are really awesome!