Copy link to clipboard
Copied
I need a script that I can run at the end of an action to rename the Background layer to the file name and move it to the top of all layers and hide visibility.
This is what I want the final document layers to look like, of course "filename" is the actual document filename. If I can change that to .jpg instead of a tif that would be very helpful too.
I'm using CC 2015 the most updated version.
I did find these scripts that aren't exactly what I need, but close, and I can't figure out how to manipulate them.
Open, Make and Rename Layer « Julieanne Kost's Blog
update: Now I'm thinking this may be totally unnecessary. The reason why I wanted the original filename.jpg was so I could export the image as an asset later down the road. I just tried creating the image asset and found that it creates a folder for each file, so if anyone can think of a better way, awesome. I was able to create an action and move all of my adjustment layers at the bottom instead of trying to move the filename layer to the top and that worked, but because each filename is different I can't select it and hide it in my action. It's a simple workaround but doesn't exactly do what I need.
Thanks!
Brandi
#target photoshop;
app.bringToFront();
if(documents.length){
var doc = activeDocument;
doc.activeLayer = doc.layers[doc.layers.length -1];
if(doc.activeLayer.isBackgroundLayer){
doc.activeLayer.name = decodeURI(doc.name).toString().replace(/\..+$/,'') + ".jpg";
doc.activeLayer.move(doc.layers[0], ElementPlacement.PLACEBEFORE);
doc.activeLayer.visible = false;
}
};
Copy link to clipboard
Copied
Here a script to select the background layer even if the document has no background layer??? Read it it may give you seome clue.
// A Script by JJMack's Designed for use with Custom Mat Actions
// This script targets the background if there is one or
// adds a new tageted background layer if there wasn't one.
// This script is supplied as is. It is provided as freeware.
// The author accepts no liability for any problems arising from its use.
// enable double-clicking from Mac Finder or Windows Explorer
#target photoshop // this command only works in Photoshop CS2 and higher
// bring application forward for double-click events
app.bringToFront();
// ensure at least one document open
if (!documents.length) {
alert('There are no documents open.', 'No Document');
}
// if at least one document exists, then proceed
else {
main();
}
///////////////////////////////////////////////////////////////////////////////
// main - main function
///////////////////////////////////////////////////////////////////////////////
function main() {
try {
// declare local variables
var layers = activeDocument.layers;
activeDocument.activeLayer = layers[layers.length-1] // Target Bottom Layer
if ( activeDocument.activeLayer.isBackgroundLayer ) { return; } // quit
app.activeDocument.artLayers.add()
// declare local variables
var newlayers = app.activeDocument.layers;
// arrange layers so new layer added is at bottom
newlayers[0].move(newlayers[newlayers.length-1], ElementPlacement.PLACEAFTER);
// Make it a Background Layer
activeDocument.activeLayer.isBackgroundLayer=1
}
// display error message if something goes wrong
catch(e) { alert(e + ': on line ' + e.line, 'Script Error', true); }
}
Copy link to clipboard
Copied
Thank you so much for your effort JJMack! However this script doesn't rename my background layer to the document name (with extension.jpg), which is the main reason I needed a script. I can create an action to move the background layer to the top no problem as long as it's named "Background".
Copy link to clipboard
Copied
#target photoshop;
app.bringToFront();
if(documents.length){
var doc = activeDocument;
doc.activeLayer = doc.layers[doc.layers.length -1];
if(doc.activeLayer.isBackgroundLayer){
doc.activeLayer.name = decodeURI(doc.name).toString().replace(/\..+$/,'') + ".jpg";
doc.activeLayer.move(doc.layers[0], ElementPlacement.PLACEBEFORE);
doc.activeLayer.visible = false;
}
};
Copy link to clipboard
Copied
I thought you wanted to script it. I see now you wanted to get someone to script it for you.
If you want to have custom you should learn a little scripting. You will not always be able to find what you want or get other to script it for you. However you may find something somewhat like what you want. With some work you may be able to modify what you found to work like you want.
Read the code. You will see some thing are easy others need a good design and lots of work.
Copy link to clipboard
Copied
I wasn't expecting anyone to script it for me at all. I stated that I didn't know how to manipulate the scripts I found in my original post. I was hoping that someone knew of a script already out there that could do something similar and I could create a work around. My philosophy is that if I've thought of doing it, someone out there probably has too AND has figured out a solution. I can read script enough to know what's going on and manipulate it a little, but I can't fully script from scratch....yet. I'm still learning. I do really appreciate your effort as I have already said.
Copy link to clipboard
Copied
If you rename the background layer and move it to th top it will always hide all the layer below because the layer you moved to the top was a background layer which did not support transparency. That is why the posted script turned the layer visibility off.
Copy link to clipboard
Copied
PERFECT! Thank you SuperMerlin I truly appreciate you doing that for me! Hopefully other people can benefit too!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now