Copy link to clipboard
Copied
Hi all,
I have a need save all my projects in a directory using the name of the main image I am working on.
Manually these are the steps I used:
I want to assign these actions to a key
Recording these steps and playing them back does not give me the results I need, snce the original name is hard-coded in the actionlist that was recorded
What should I be doing instead ?
Thanks in advance !
Copy link to clipboard
Copied
You don’t mention which format the original file is (and figuring that and its current settings out seems too much of a hassle to me) so this would only save the jpgs into the folder (and create one if it does not exist).
If you want to give it a try, paste the following text into a new file in ExtendScript Toolkit (part of Photoshop’s installation, Applications/Utilities/Adobe Utilities/ExtendScript Toolkit CS4 or /Applications/Utilities/Adobe Utilities-CS5/ExtendScript Toolkit CS5) and save it as a jsx-file into Photoshop’s Presets/Scripts-folder.
After restarting Photoshop the Script should be available under File > Scripts and can be assigned a Keyboard Shortcut directly, recorded into an Action, (in CS4 and CS5) be used in a Configurator-Panel or started from ExtendScript Toolkit directly.
// saves jpg into folder of file’s name next to file;
// be advised: this overwrites existing jpgs of the same name without prompting;
// thanks to xbytor;
// 2012, use it at your own risk;
#target photoshop;
if (app.documents.length > 0) {
var thedoc = app.activeDocument;
// getting the name and location;
var docName = thedoc.name;
if (docName.indexOf(".") != -1) {var basename = docName.match(/(.*)\.[^\.]+$/)[1]}
else {var basename = docName};
// getting the location, if unsaved save to desktop;
try {var docPath = thedoc.path}
catch (e) {var docPath = "~/Desktop"};
// create folder if it does not exist;
var folderString = docPath+"/"+basename;
if (Folder(folderString).exists == false) {new Folder(folderString).create()};
// jpg options;
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 12;
jpegOptions.embedColorProfile = true;
jpegOptions.matte = MatteType.NONE;
//save jpg as a copy:
thedoc.saveAs((new File(folderString+"/"+basename+".jpg")),jpegOptions,true);
};
Copy link to clipboard
Copied
Hey hey ! your script works great ! Thank you for your work !
The problem is, it's not working when you select multiple files (it creates a folder for every file )
But, I want to move 25 files into just ONE folder.
Files in my case are like this :
NFGFSHTEFD-1.jpg
NFGFSHTEFD-2.jpg
NFGFSHTEFD-3.jpg
NFGFSHTEFD-4.jpg
NFGFSHTEFD-5.jpg
NFGFSHTEFD-6.jpg
NFGFSHTEFD-7.jpg
....
NFGFSHTEFD-25.jpg
Please help me, or point me to the correct path !
Thanks and greetings from Germany
Adrian
Copy link to clipboard
Copied
Hi cinevaa77289409,
You need to replace this code
if (docName.indexOf(".") != -1) {var basename = docName.match(/(.*)\.[^\.]+$/)[1]}
else {var basename = docName};
to this code
var docName = (thedoc.name).replace(/\.[^\.]+$/, '');
if(basename.indexOf("-")!=-1){basename=docName.substring(0,docName.indexOf("-"));}
else{basename=docName;}
this script will move that 25 files into one folder.
Regards,
yajiv
Copy link to clipboard
Copied
Hi Natrev,
thank you for your help,
unfortunately it gives me an error on line 11 : "Error 2 : basename undefined"
can't figure it out what's wrong
hope you can help me
thank you !
Copy link to clipboard
Copied
Hi,
Sorry the that code. Please use this code
- if (docName.indexOf(".") != -1) {var basename = docName.match(/(.*)\.[^\.]+$/)[1]}
- else {var basename = docName};
to this code
var docName = (thedoc.name).replace(/\.[^\.]+$/, '');
if(docName.indexOf("-")!=-1){var basename=docName.substring(0,docName.indexOf("-"));}
else{var basename=docName}
-yajiv
Copy link to clipboard
Copied
Hi again Natrev !
it's working but again it creates a folder for every single file, so if I have 25 files, it creates 25 folders...
I just want to move all 25 files into ONE folder based on the name of the file BLABLABLA
but, hey, thank you so much for a quick answer !!!
greetings form Germany !
Adrian
Copy link to clipboard
Copied
Hi Adrian,
Try this code. its working.. if the file name is NFGFSHTEFD-1.jpg, NFGFSHTEFD-2.jpg....NFGFSHTEFD-25.jpg..
#target photoshop;
if (app.documents.length > 0) {
var thedoc = app.activeDocument;
// getting the name and location;
var docName = thedoc.name;
var basename;
var docName = (thedoc.name).replace(/\.[^\.]+$/, '');
if(docName.indexOf("-")!=-1){var basename=docName.substring(0,docName.indexOf("-"));}
else{var basename=docName}
// getting the location, if unsaved save to desktop;
try {var docPath = thedoc.path}
catch (e) {var docPath = "~/Desktop"};
// create folder if it does not exist;
var folderString = docPath+"/"+basename;
if (Folder(folderString).exists == false) {new Folder(folderString).create()};
// jpg options;
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 12;
jpegOptions.embedColorProfile = true;
jpegOptions.matte = MatteType.NONE;
//save jpg as a copy:
thedoc.saveAs((new File(folderString+"/"+docName+".jpg")),jpegOptions,true);
};
- yajiv
Copy link to clipboard
Copied
You are the man !!!!
Thank you !!! Vielen Dank !!!
can't tell you how much time you save me !!!
Thank you Natrev !
Copy link to clipboard
Copied
Hi Adrian,
Can you please mark correct answer for c.pfaffenbichler post. I have only done some slight change based on your requirement.
-yajiv
Copy link to clipboard
Copied
c.pfaffenbichler​ correct answer ! thank you also natrev​ for sorting it out for my requirement !