Photoshop JSX -- 如何将任意文本复制到剪贴板?

发布于 2024-09-29 15:41:50 字数 348 浏览 4 评论 0原文

现在,我使用提示命令作为解决方法,从 Photoshop 中的 JSX 脚本中复制任意文本。

prompt("to copy",(horizontalcenter.toString()) + ", " + verticalcenter.toString());

这给了我我想要的信息。 “复制”只是给出了标题,那么我要从Photoshop中复制出来的信息就在已经选中的提示框中。因此,我所要做的就是点击 Control C,转到需要此信息的 Notepad++,然后点击 Control V。

它可以工作,但可能会更快。必须有一种方法可以将这些信息从 Photoshop 直接复制到剪贴板,不是吗?

Right now I am using the prompt command as a workaround to copy arbitrary text out of my JSX script in Photoshop.

prompt("to copy",(horizontalcenter.toString()) + ", " + verticalcenter.toString());

And that is giving me the information that I want. The "to copy" just gives the title, then the information I want to copy out of Photoshop is in the prompt box already selected. So all I have to do is hit control C, go to Notepad++ where I need this information, and hit control V.

It works, but it could be faster. There has to be a way to copy this information out of Photoshop straight to the clipboard, no?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深海里的那抹蓝 2024-10-06 15:41:50

Photoshop 13.1(Photoshop CS6 的最新 Creative Cloud 版本)现在有一个挂钩,允许您直接执行此操作。这是一个示例函数:

function copyTextToClipboard( txt )
{
    const keyTextData         = app.charIDToTypeID('TxtD');
    const ktextToClipboardStr = app.stringIDToTypeID( "textToClipboard" );

    var textStrDesc = new ActionDescriptor();

    textStrDesc.putString( keyTextData, txt );
    executeAction( ktextToClipboardStr, textStrDesc, DialogModes.NO );
}

请注意,这在 13.1 之前的 Photoshop 版本中不起作用

Photoshop 13.1 (the latest Creative Cloud release of Photoshop CS6) now has a hook allowing you to do this directly. Here's a sample function:

function copyTextToClipboard( txt )
{
    const keyTextData         = app.charIDToTypeID('TxtD');
    const ktextToClipboardStr = app.stringIDToTypeID( "textToClipboard" );

    var textStrDesc = new ActionDescriptor();

    textStrDesc.putString( keyTextData, txt );
    executeAction( ktextToClipboardStr, textStrDesc, DialogModes.NO );
}

Please note this won't work in versions of Photoshop prior to 13.1

万人眼中万个我 2024-10-06 15:41:50

在 Photoshop 脚本论坛上找到了答案。

http ://ps-scripts.com/bb/viewtopic.php?f=9&t=3097&p=15324&hilit=clipboard&sid=1b1cc023023b9f91ab46e30e48e2ab53#p15324

function copyTextToClipboard(text)
{
   var folderForTempFiles = Folder.temp.fsName;

   // create a new textfile and put the text into it
   var clipTxtFile =new File(folderForTempFiles + "/ClipBoard.txt"); 
   clipTxtFile.open('w'); 
   clipTxtFile.write(text); 
   clipTxtFile.close();

   // use the clip.exe to copy the contents of the textfile to the windows clipboard
   var clipBatFile =new File(folderForTempFiles + "/ClipBoard.bat"); 
   clipBatFile.open('w'); 
   clipBatFile.writeln("cat \"" + folderForTempFiles + "/ClipBoard.txt\"|clip"); 
   clipBatFile.close(); 
   clipBatFile.execute();
}

它将您要复制的文本放入临时文本文件,然后从该文本文件复制它。我什至不知道你可以将文本放入文本文件中。显然 Photoshop 中的 javascript 功能比我想象的要强大得多!

Found the answer on a Photoshop scripting forum.

http://ps-scripts.com/bb/viewtopic.php?f=9&t=3097&p=15324&hilit=clipboard&sid=1b1cc023023b9f91ab46e30e48e2ab53#p15324

function copyTextToClipboard(text)
{
   var folderForTempFiles = Folder.temp.fsName;

   // create a new textfile and put the text into it
   var clipTxtFile =new File(folderForTempFiles + "/ClipBoard.txt"); 
   clipTxtFile.open('w'); 
   clipTxtFile.write(text); 
   clipTxtFile.close();

   // use the clip.exe to copy the contents of the textfile to the windows clipboard
   var clipBatFile =new File(folderForTempFiles + "/ClipBoard.bat"); 
   clipBatFile.open('w'); 
   clipBatFile.writeln("cat \"" + folderForTempFiles + "/ClipBoard.txt\"|clip"); 
   clipBatFile.close(); 
   clipBatFile.execute();
}

It's placing the text you want to copy in a temp text file, then copying it from that text file. I didn't even know you could place text into a text file. Apparently the javascript capabilities in Photoshop are much more powerful than I realized!

静若繁花 2024-10-06 15:41:50
function addToClipBoard(text) {
    app.system("echo " + text + "| clip");
}
function addToClipBoard(text) {
    app.system("echo " + text + "| clip");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文