Copy link to clipboard
Copied
I am wondering if any one can help me, I have an action that need to save jpg as active or top layer name, below is the code that i have using for change name from file name to layer name so now i want to save file as active layer name....
I have tried every thing but not get any clues please help if you can?
var idoc = app.activeDocument;
idoc.activeLayer.name = idoc.name.slice(0, idoc.name.lastIndexOf ("."));
There is a slight mistake in his script try this. I just change path to docpath "path" must be a reserved name or there is an error in Adobe scripting plug-in.
var doc = app.activeDocument;
var docpath = doc.path;
var activeLayer = doc.activeLayer;
var saveFile = File(docpath + "/" + activeLayer.name + ".jpg");
saveJPG(saveFile, 10)
function saveJPG(saveFile, jpegQuality) {
var jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOp
...Copy link to clipboard
Copied
There you go. It saves as JPEG image.
var doc = app.activeDocument;
var path = doc.path;
var activeLayer = doc.activeLayer;
var saveFile = File(path + "/" + activeLayer.name + ".jpg");
saveJPG(saveFile, 10)
function saveJPG(saveFile, jpegQuality) {
var jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
};
Copy link to clipboard
Copied
Thank you so much "Tomas" for your quick help, I have run this script but not thing happen when run this script, I have no idea where is the file is saved?
I just want to save document with active layer's name only not final file or final result, because there many other layers etc i just want to save file with the name of top layer... I have attaching my .psd file for review.
Actually I want to replace 3d screen image with new images, so i have smart object to change image but there is no way to save 3d screen with new inserted image, currently I'm using this script to change document name by layer name and then duplicate layer to main document and then hide duplicated layer so this hidden layer having actual name which i wan to save final document...
current script to change layer name with document.
Copy link to clipboard
Copied
File is being saved to same location where your original PSD file is. And it does exactly what you asked in your first request - save jpg as active or top layer name
Copy link to clipboard
Copied
I'm really sorry, I have checked but the source folder of PSD file is blank and file not saving, I'm sure i am doing some thing wrong....
Copy link to clipboard
Copied
Tomas does not save me to the original folder
But I saw that it saves the file in the photoshop installation folder
Copy link to clipboard
Copied
There is a slight mistake in his script try this. I just change path to docpath "path" must be a reserved name or there is an error in Adobe scripting plug-in.
var doc = app.activeDocument;
var docpath = doc.path;
var activeLayer = doc.activeLayer;
var saveFile = File(docpath + "/" + activeLayer.name + ".jpg");
saveJPG(saveFile, 10)
function saveJPG(saveFile, jpegQuality) {
var jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
};
Copy link to clipboard
Copied
Thank you so much JJMack​you save my day! Yes that is some thing that exactly i needed. Thank you for your great help...
Copy link to clipboard
Copied
Thanks Mack for your script... script works correctly, I just having one issue, file will saving just one fiile which i have put when create action means if i run second time action will not change file name...
Here is my steps, first i change smart object open new image ctrl + A, copy image and past to smart object and rename layer of new image's by this script :
and duplicate this new named layer to main mock up so this layer show at top of layer panel and click eye button of layer to hide this layer content and finally save this file via your above script and last step to delete this duplicate layer and stop action...
But problem is file will saving for first named layer and not changing when run second time?
Copy link to clipboard
Copied
Replacing the contents of a smart object layer. Its object requires a replacement objects the is the sames size ad the original object. For there is an associated transform for the smart object which doe not get replaced. Also the Smart Object Layer name is not replaced. You would need to change the layer name when you replace its content. If you want to automate the process scripting it would be your best option. Scripts can use logic to get at file names and layer names and use them in their processing. If you want only to record and edit action you should look into Scripts that you can add you actions to like the Image processor and Image Processor Pro scripts. These can process your image files and save output image files you want that are the file type yow want with the names you want and fitted to any size you want. The Scripts do all the hard part. You can add actions to add your customization.
You would not however be able to process a Template psd file you populate with replacement images into a template smart object layer. You would need to Script the whole process. Something like my Batch populating scripts but with some template design that employs smart object layers designed the have their contents replaced soy the images will be transformed like the original object.
My scripts do not do that. My Template design is very simple they just contain Alpha channels named Image 1, Image 2, ...; Image N that map the location size and shape of where image should be populated. Image Files are just placed in as smart object layers sized positions and mask to shape using the Alpha channels maps. The smart object layer transform are simply a straight size and position transform no distortion like rotation and perspective is supported. That can be done later manually if needed by editing the populated layered template and changing the transforms the script created.
Copy link to clipboard
Copied
JJMack​ I wonder if you could help solve a scripting/action question similar to the one on this thread. I have been using Generate Assets but can't rely on the color quality in output files.
I set up an action exporting groups (they are closed) one at a time with Save for Web Legacy which preserves the colors and uses the settings I want BUT the saved files are saved with the name of the source file instead of the group name. I tried toggling Dialog in the actions so I can write the name of each file but I know there has to be a more elegant way to do this after reading your answer.
I am looking for a script to replicate what Generate Assets does for selected groups or layers BUT using an action or a saved Save for Web Legacy settings. The goal is to automate the save for web Legacy using the Group Name of the top layer, close the layer and select the layer below, then start over.
-C
Copy link to clipboard
Copied
I don't enable the Generate Plug-in. I do not know how generate works. Actions can not use logic to create output file names, scripts can. If you do not know how to program a Photoshop script. You may be able to use a script like Image Processor or Image Processor Pro to save your output files that are created by your actions. Action create. you cans include actions in the processing of your image files. Image Processor Pro has more options. However, I feel you will most likely need a custom script.
Copy link to clipboard
Copied
Thank you JJMack​. This is very helpful. Would you happen to know where I can find someone who writes PSD Scripts?
-C
Copy link to clipboard
Copied
If you have scripting question ask them in the forum. To write a Photoshop you need to know how Photoshop works well and you need to be able to program using JavaScript. Scripts are programs you need to have programming skills.
Copy link to clipboard
Copied
File menu > Export > Layers to files
Or you could try the Layer Saver or Layer Saver Plus scripts from Paul Riggott:
GitHub - Paul-Riggott/PS-Scripts: Photoshop Scripts
Or perhaps try some scripts mentioned here:
Copy link to clipboard
Copied
Actually I want to replace 3d screen image with new images, so i have smart object to change image but there is no way to save 3d screen with new inserted image, currently I'm using this script to change document name by layer name and then duplicate layer to main document and then hide duplicated layer so this hidden layer having actual name which i wan to save final document...
That sound like you want to replace an image that is part of a composite or image document. Replace a layer. Have you look at Photoshop's data-driven graphics feature or looked for a script that will batch populate a Photoshop PSD template file.
Also when replacing the contents of a smart object layer the replacement object file needs to be the same size as the original file so the smart object layer associated transform will work correctly. So I do not think data-driven graphics variable can be a smart object layer. I also do not know of any Photoshop script that has been made public the batch replaces smart object layers contents. If you do not need the images to be transformed like rotate and perspective you would be more likely find a script the can replace pixel image layers or place in image smart object layers that are sized and masked to shaped.
For example the batch scripts in my Photoshop Photo Collage toolkit.
Photo Collage Toolkit
Photoshop scripting is powerful and I believe this package demonstrates this
The package includes four simple rules to follow when making Photo Collage Template PSD files so they will be compatible with my Photoshop scripts.
There are fifteen scripts in this package they provide the following functions: