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

copy the layer name to the clipboard uxp

Engaged ,
Dec 22, 2024 Dec 22, 2024

Copy link to clipboard

Copied

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?

TOPICS
Actions and scripting

Views

226

Translate

Translate

Report

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 23, 2024 Dec 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.

Votes

Translate

Translate
Adobe
Community Expert ,
Dec 22, 2024 Dec 22, 2024

Copy link to clipboard

Copied

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"
}, 

Votes

Translate

Translate

Report

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
Engaged ,
Dec 23, 2024 Dec 23, 2024

Copy link to clipboard

Copied

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"
      ]
    }
  ]
}

 

Votes

Translate

Translate

Report

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 23, 2024 Dec 23, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Engaged ,
Dec 23, 2024 Dec 23, 2024

Copy link to clipboard

Copied

perfect now it works like a charm
thanks for the help

Votes

Translate

Translate

Report

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 23, 2024 Dec 23, 2024

Copy link to clipboard

Copied

@sttk3 

 

I just wanted to say thank you for stopping by and sharing your knowledge and experience with UXP.

 

This sort of involvement is the only thing that will help advance UXP scripting, the official documentation is "somewhat lacking" – we truly need selfless evangelists and mentors to step up and help transition ExtendScript script coders to UXP scripting (forgetting plugins/panels for the moment).

 

As this topic demonstrates, even something as "simple" as copying a text string to the clipboard in ExtendScript is tortuous in UXP. Saving files is just as esoteric and impossible for a UXP beginner to fathom.

Votes

Translate

Translate

Report

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 23, 2024 Dec 23, 2024

Copy link to clipboard

Copied

ExtendScript and ActionDescriptor are still available and will live on in Photoshop for some time. Perhaps UXP may even have a shorter lifespan in comparison.

 

If you want to migrate, that's fine, but if you want to stay in fact, don't rush. You can already write programs, so if it really becomes necessary to migrate to a other platforms, you will be able to move quickly.

Votes

Translate

Translate

Report

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 23, 2024 Dec 23, 2024

Copy link to clipboard

Copied

@sttk3 

 

I admire your optimism and confidence!  :]

 

I'm looking forward to somebody creating a converter for legacy DOM/AM code to update it for UXP/BatchPlay... But I'm not holding my breath!

Votes

Translate

Translate

Report

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 23, 2024 Dec 23, 2024

Copy link to clipboard

Copied

Photoshop already allows recording ActionDescriptor from the plugin menu, and the Actions panel allows conversion from actions to code for batchPlay.

 

Jarda is an expert in this area and there are numerous tools available.

 

The necessary tools are already available.

Votes

Translate

Translate

Report

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
Engaged ,
Dec 24, 2024 Dec 24, 2024

Copy link to clipboard

Copied

Uso uxp da 2 anni ormai, all'inizio è stato difficile capire questo nuovo modo, ma ora sembra andare bene, riesco a fare quasi tutto quello che facevo in Java. Il problema più grande che ho trovato è che sul forum java tutti cercano di aiutare, sul sito di sviluppo uxp non sono molto collaborativi nell'aiutare e ti danno sempre un link alla documentazione senza quasi mai darti un prodotto funzionante, Un'altra cosa, uxp essendo giovane e molto delicato, quando esce una nuova versione di photoshop è probabile che ci sia qualcosa che non va nel pannello. Onestamente, java è ancora superiore a uxp, ma anche se ero abbastanza esperto con java, uxp ha un potenziale superiore e non penso di tornare a java. Secondo me la cosa che dovrebbe fare adobe è far coesistere i 2 sistemi.

Votes

Translate

Translate

Report

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 24, 2024 Dec 24, 2024

Copy link to clipboard

Copied

UXP developers are more like programmers than those of ExtendScript. Probably they can understand it just by looking at the documentation. It is challenging for us.

Votes

Translate

Translate

Report

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
Engaged ,
Dec 24, 2024 Dec 24, 2024

Copy link to clipboard

Copied

You're absolutely right, but many times a little help or a few lines of code would bring users closer to switching to uxp. I also understand that developement users are professionals and create paid panels and must be a little jealous of their knowledge.

Votes

Translate

Translate

Report

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 24, 2024 Dec 24, 2024

Copy link to clipboard

Copied

quote

Photoshop already allows recording ActionDescriptor from the plugin menu, and the Actions panel allows conversion from actions to code for batchPlay.


Agreed, but it's not always that simple.

 

In Legacy ES, it's easy to save a file with or without a dialog to disk, either using DOM or using ScriptingListener code.

 

The same can't be said for UXP in my admittedly small knowledge and experience.

 

I can record an action that successfully saves a file to a given location.

 

If I use Photoshop to create BatchPlay or use Alchemist to do so, the code doesn't execute, no file is saved. I believe that I need a manifest file or something else?

 

For me, UXP has a high cost of entry. So high as to be prohibitive.

 

 

Votes

Translate

Translate

Report

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 24, 2024 Dec 24, 2024

Copy link to clipboard

Copied

Nowadays, files can be saved without dialogs, but that is something that many developers struggle with and many questions and answers to the forum about it. I have also answered many of them.

 

Frankly, I am tired of this topic, so I say, “Could you please search the Creative Cloud Developer Forum?”

Votes

Translate

Translate

Report

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 24, 2024 Dec 24, 2024

Copy link to clipboard

Copied

LATEST
quote

Nowadays, files can be saved without dialogs, but that is something that many developers struggle with and many questions and answers to the forum about it. I have also answered many of them.

 

Frankly, I am tired of this topic, so I say, “Could you please search the Creative Cloud Developer Forum?”


By @sttk3

 

Thank you, I understand and yes, I have searched that forum before and will likely do so again in the future. Again, I thank you for your time and advice.

Votes

Translate

Translate

Report

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