Skip to main content
Inspiring
December 22, 2024
Answered

copy the layer name to the clipboard uxp

  • December 22, 2024
  • 1 reply
  • 1279 views

copy the layer name to the clipboard uxp
in java the command was this:

var doc = activeDocument;
var aLayer = doc.activeLayer.name;
var d = new ActionDescriptor();  
d.putString(stringIDToTypeID("textData"), aLayer);  
executeAction(stringIDToTypeID("textToClipboard"), d, DialogModes.NO); 

 

in uxp I tried this and it doesn't work,

const { app } = require("photoshop");
const doc = app.activeDocument;
const activeLayer = doc.activeLayer.name;
const layerName = activeLayer.name;
clipboard.writeText(layerName);

any ideas?

Correct answer sttk3

The manifest.json needs to be v5, as a prerequisite. Can you show me the json you tried with v5? And if there are any error messages, please share those as well.

 

I confirmed that it works with Photoshop 2025 (26.1.0) before posting, just a note to clarify.

1 reply

Legend
December 23, 2024
It probably depends on your version of Photoshop, for 2025 (v26) try something like this. The document is here.
// JavaScript

const { app, core } = require('photoshop') ;

const main = async () => {
  try {
    await core.executeAsModal(
      async (context) => {
        const doc = app.activeDocument ;
        const layerName = doc.activeLayers[0].name ;
        const clipboard = navigator.clipboard ;
        const dataTransferProviders = {
          'text/plain': layerName
        } ;
        await clipboard.writeText(dataTransferProviders) ;
        app.showAlert(`Copied to clipboard\n'${layerName}'`) ;
      }, 

      {
        'commandName': 'Copy Layer Name'
      }
    ) ;
  } catch(e) {
    console.log(e) ;
  }
} ;
// manifest.json

"requiredPermissions": {
  "clipboard": "readAndWrite"
}, 
Inspiring
December 23, 2024

sttk3
i tried your code, but it doesn't work,
i tried it on photoshop 2023, 2024 and 2025,

I also tried with manifest 5 and api 2

 

this is the manifest file

{
  "id": "Test",
  "name": "Test",
  "version": "2.0.0",
  "main": "index.html",
  "host": {
    "app": "PS",
    "minVersion": "23.3.2"
  },
  "manifestVersion": 4,
  "requiredPermissions": {
    "allowCodeGenerationFromStrings": false,
    "clipboard": "readAndWrite",
    "launchProcess": {
      "schemes": [
        "https",
        "mailto",
        "file"
      ],
      "extensions": [
        ".icc",
        ".3DL",
        ".cube",
        ".look",
      ".jpg",
        ".psd",
        ".pdf",
        ".txt",
        ".doc",
        ".xls",
        ".csv",
        ""
      ]
    },
    "ipc": {
      "enablePluginCommunication": false
    },
    "localFileSystem": "fullAccess",
    "network": {
      "domains": [
        "Test"
      ]
    },
    "webview": {
      "allow": "yes",
      "domains": [
        "https://google.com",
        "https://*.google.com"
      ]
    }
  },
  "entrypoints": [
    {
      "type": "panel",
      "id": "Test",
      "label": {
        "default": "Test"
      },
      "minimumSize": {
        "width": 300,
        "height": 240
      },
      "maximumSize": {
        "width": 300,
        "height": 240
      },
      "preferredDockedSize": {
         "width": 300,
        "height": 240
      },
      "preferredFloatingSize": {
         "width": 300,
        "height": 240
      },
      "icons": [
        {
          "width": 23,
          "height": 23,
          "path": "icons/dark.png",
          "scale": [
            1,
            2
          ],
          "theme": [
            "darkest",
            "dark",
            "medium"
          ]
        },
        {
          "width": 23,
          "height": 23,
          "path": "icons/light.png",
          "scale": [
            1,
            2
          ],
          "theme": [
            "lightest",
            "light"
          ]
        }
      ]
    }
  ],
  "icons": [
    {
      "width": 48,
      "height": 48,
      "path": "icons/plugin-icon.png",
      "scale": [
        1,
        2
      ],
      "theme": [
        "darkest",
        "dark",
        "medium",
        "lightest",
        "light",
        "all"
      ],
      "species": [
        "pluginList"
      ]
    }
  ]
}

 

sttk3Correct answer
Legend
December 23, 2024

The manifest.json needs to be v5, as a prerequisite. Can you show me the json you tried with v5? And if there are any error messages, please share those as well.

 

I confirmed that it works with Photoshop 2025 (26.1.0) before posting, just a note to clarify.