【问题标题】:AE Extendscript text layer cursor controlAE Extendscript文字图层光标控制
【发布时间】:2013-06-27 15:31:39
【问题描述】:

我正在尝试使用 AE Extendscript 将一些文本从 AE 复制到系统剪贴板。 After Effects 没有直接在 Extendscript 中提供此功能。

我可以将文本放在文本层上,然后将其复制到剪贴板:

app.executeCommand(app.findMenuCommandId("Copy"));  

但要做到这一点,必须选择文本。 可以通过以下方式完成:

app.executeCommand(app.findMenuCommandId("Select All"));   

但是,光标必须在字段中才能工作。

我正在尝试在 After Effects 中使用 Extendscript 将光标放置在 textlayer 文本字段中。 反正我看不到这样做。

我已经设法使用 .bat 方法将变量的值复制到系统剪贴板,但这不适用于所有系统。最好的方法是真正留在 AE 中。

有谁知道如何在 AE Extendscript 中控制文本光标?

有什么想法吗?

【问题讨论】:

  • 这不是答案,但您需要使用光标吗?您可以通过 sourceText 属性从 TextLayer 获取文本: if((app.project.activeItem.selectedLayers[0] instanceof TextLayer)){ alert(app.project.activeItem.selectedLayers[0].sourceText.value); }
  • 是的,但无法在代码中将其复制到剪贴板。在不创建 .bat 文件或苹果脚本文件的情况下做到这一点的唯一方法是以某种方式选择文本,然后使用上面的 app.execute...copy 命令。

标签: extendscript after-effects


【解决方案1】:

使用 vbs 脚本和sendkeys 怎么样?您可以创建脚本来执行 sendkeys 的事情(因为您不能在 javascript 中执行此操作),然后让您的 javascript 文件在适当的位置调用 vbs 脚本。

【讨论】:

  • 我正试图让它在不同的平台上工作,我想既然我已经用 .bat 文件让它在 Win 上工作,也许有人已经找到了一个等效的 applescript。
  • 你不能用javascript做sendkeys;我想你已经知道了。嗯嗯。
【解决方案2】:

这是在 Extendscript 中的工作原理:

//This works on Vista and Win 7,  XP requires the user to copy 'clip.exe' to the 'sys32' folder.
function copyTextToClipboard2(text)
{
   var folderForTempFiles = Folder.temp.fsName;
   //alert(folderForTempFiles)
   // 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("clip < " + folderForTempFiles + "/ClipBoard.txt"); 
   clipBatFile.close(); 
   clipBatFile.execute();
}

有没有苹果的同类产品?

【讨论】:

  • 我无意中发布了上面的Mac版本。它在不使用控制台或终端的情况下运行良好。它使用:“system.callSystem”和“pbcopy”。不过,我似乎无法使用“clip.exe”获得 Windows 版本。我将 Windows 问题移至此处的新问题:link
【解决方案3】:

我在 Mac 上的 After Effects CC 上对此进行了测试,效果很好:

text = 'Lets copy some 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();

system.callSystem("cat " + folderForTempFiles + "/ClipBoard.txt" + " | pbcopy");

【讨论】:

  • 我在 Windows 上尝试了同样的事情,使用 'clip' 而不是 'pbcopy',但无论我尝试什么,我都无法让 'system.callSystem' 与 'clip' 一起工作。它在 Windows 上被阻止了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-19
  • 1970-01-01
  • 2021-11-15
  • 2012-10-29
  • 2010-11-20
相关资源
最近更新 更多