Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Change default background layer to original file name

Explorer ,
Dec 20, 2021 Dec 20, 2021

When I import a file into photoshop, can I have the "background" layer show the PSD file name? 

* Inventory: Photoshop v 24.3.0; M1 Mac Mini, Ventura 13.2.1, 1 TB SSD, 16 GB RAM; Wacom Intuos Pro M
TOPICS
Actions and scripting , macOS
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 20, 2021 Dec 20, 2021

Yes it works. The basic script is installed by default with Photoshop. More on Script Events Manager here:

 

https://prepression.blogspot.com/2021/10/photoshop-script-events-manager.html

 

EDIT: Recently discussed in this recent topic thread -

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-for-open-as-layer-without-file-extension/m-p/12594732

 

Translate
Adobe
LEGEND ,
Dec 20, 2021 Dec 20, 2021

You don't import a file, you just open it. And a background layer can't have a different name or it won't be a background layer. I suppose you could add an empty layer to every file with the filename, but why?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 20, 2021 Dec 20, 2021

When I'm compositing, I'd like the background layer to show the original filename similiar to when you load files into a stack. 

 

 

* Inventory: Photoshop v 24.3.0; M1 Mac Mini, Ventura 13.2.1, 1 TB SSD, 16 GB RAM; Wacom Intuos Pro M
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 20, 2021 Dec 20, 2021

You can convert  a background layer to a normal layer and name it anyway you want.  All PSD do not have a background layer.  The background layer is special bottom layer and one is not required.   You can script the process even make an open event handler. But you need to handle what you want to do when there is no background layer. You will be making all PSD to not have as background layer you will most likely open these also and If you save the PSD with a new file name will you also be renaming the bottom layer. Save even handlers are triggered after the save completes the rename can not be done by  a save even handler the documen may not longer be in Photoshop. The open event handler  can rename a bottom normal layer.  The open event handler would need to be a script so it can use logic to determine what kind of layer the bottom layer is in  a PSD file and be able to retrieve the backing file name and file type,

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 20, 2021 Dec 20, 2021

I think this is what I'm looking for 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/renaming-a-layer-with-the-file-name/t...

 

Does anyone know if this works for 23.1.0? 

* Inventory: Photoshop v 24.3.0; M1 Mac Mini, Ventura 13.2.1, 1 TB SSD, 16 GB RAM; Wacom Intuos Pro M
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 20, 2021 Dec 20, 2021

Yes it works. The basic script is installed by default with Photoshop. More on Script Events Manager here:

 

https://prepression.blogspot.com/2021/10/photoshop-script-events-manager.html

 

EDIT: Recently discussed in this recent topic thread -

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-for-open-as-layer-without-file...

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 21, 2021 Dec 21, 2021

That was perfect! Thanks! Is it possible to add "lock layer" step to the end of that script? 

* Inventory: Photoshop v 24.3.0; M1 Mac Mini, Ventura 13.2.1, 1 TB SSD, 16 GB RAM; Wacom Intuos Pro M
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 21, 2021 Dec 21, 2021

@ipv1 wrote:

That was perfect! Thanks! Is it possible to add "lock layer" step to the end of that script? 


 

Sure, here is a function with the various parameters to swap in/out:

 

lockLayer("protectAll");

function lockLayer(protectStringValue) {
    // "protectTransparency"
    // "protectComposite"
    // "protectPosition"
    // "protectArtboardAutonest"
    // "protectAll"
    var idapplyLocking = stringIDToTypeID("applyLocking");
    var desc549 = new ActionDescriptor();
    var idnull = stringIDToTypeID("null");
    var ref127 = new ActionReference();
    var idlayer = stringIDToTypeID("layer");
    var idordinal = stringIDToTypeID("ordinal");
    var idtargetEnum = stringIDToTypeID("targetEnum");
    ref127.putEnumerated(idlayer, idordinal, idtargetEnum);
    desc549.putReference(idnull, ref127);
    var idlayerLocking = stringIDToTypeID("layerLocking");
    var desc550 = new ActionDescriptor();
    var idprotectTransparency = stringIDToTypeID(protectStringValue);
    desc550.putBoolean(idprotectTransparency, true);
    var idlayerLocking = stringIDToTypeID("layerLocking");
    desc549.putObject(idlayerLocking, idlayerLocking, desc550);
    executeAction(idapplyLocking, desc549, DialogModes.NO);
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 21, 2021 Dec 21, 2021

Awesome! This makes me want to go down further into the scripts rabbit hole. Appreciate your help on this. Cheers

 

* Inventory: Photoshop v 24.3.0; M1 Mac Mini, Ventura 13.2.1, 1 TB SSD, 16 GB RAM; Wacom Intuos Pro M
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 21, 2021 Dec 21, 2021

Okay, I have one more request. Can I add layer mask to that background layer before locking it? Thank you thank thank you!

* Inventory: Photoshop v 24.3.0; M1 Mac Mini, Ventura 13.2.1, 1 TB SSD, 16 GB RAM; Wacom Intuos Pro M
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 21, 2021 Dec 21, 2021

Yes, I'll post the code tomorrow, bed calls!

 

Do you need a white or black mask? Is this based off a selection or just the entire layer?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 21, 2021 Dec 21, 2021

just a white mask, entire layer. thanks so much! 

* Inventory: Photoshop v 24.3.0; M1 Mac Mini, Ventura 13.2.1, 1 TB SSD, 16 GB RAM; Wacom Intuos Pro M
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 21, 2021 Dec 21, 2021

Do you want a regular layer of a background layer? A background layer can't have a mask.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 21, 2021 Dec 21, 2021

Here you go:

 

addMask("revealAll");

function addMask(maskVisibility) {
    // maskVisibility = "revealAll" or "hideAll"
    if (!app.activeDocument.activeLayer.isBackgroundLayer) {
        var c2t = function (s) {
            return app.charIDToTypeID(s);
        };
        var s2t = function (s) {
            return app.stringIDToTypeID(s);
        };
        var descriptor = new ActionDescriptor();
        var reference = new ActionReference();
        descriptor.putClass(s2t("new"), s2t("channel"));
        reference.putEnumerated(s2t("channel"), s2t("channel"), s2t("mask"));
        descriptor.putReference(s2t("at"), reference);
        descriptor.putEnumerated(s2t("using"), c2t("UsrM"), s2t(maskVisibility));
        executeAction(s2t("make"), descriptor, DialogModes.NO);
    }
    else {
       //alert("The active layer is a Background layer!");
    }
}

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 22, 2021 Dec 22, 2021

You're the best! Appreciate all your help - happy holidays sir 

 

* Inventory: Photoshop v 24.3.0; M1 Mac Mini, Ventura 13.2.1, 1 TB SSD, 16 GB RAM; Wacom Intuos Pro M
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 03, 2022 Jan 03, 2022
LATEST

Just in case somebody is looking for "standard code":

 

app.activeDocument.activeLayer.allLocked = true; 

app.activeDocument.activeLayer.pixelsLocked = true;

app.activeDocument.activeLayer.positionLocked = true;

app.activeDocument.activeLayer.transparentPixelsLocked = true;

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 20, 2021 Dec 20, 2021

A conditional action can check for the Background layer and promote it to a standard layer, it just can't name it after the open document name, a script is required for that. This is one of the "rare" cases where the conditional actions are useful:

 

layer2bg.png

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines