现在我使用prompt命令作为解决方法,在Photoshop中从我的JSX脚本中复制任意文本。
prompt("to copy",(horizontalcenter.toString()) + ", " + verticalcenter.toString());
这就是给我我想要的信息。 “复制”只是给出了标题,然后我要复制出Photoshop的信息就在已经选中的提示框中。所以我要做的就是点击控制C,转到Notepad ++,我需要这些信息,并点击控制V。
它有效,但可能会更快。必须有一种方法可以将这些信息直接从Photoshop复制到剪贴板,不是吗?
答案 0 :(得分:6)
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版本
答案 1 :(得分:4)
在Photoshop脚本论坛上找到答案。
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功能比我意识到的要强大得多!