Skip to main content
Inspiring
October 15, 2024
Question

How can I paste text using a hotkey into text with all characters selected by a script?

  • October 15, 2024
  • 1 reply
  • 169 views

In the text, all characters have been selected using the following code

 

 

 

 

textFrame.textRange.select();

 

 

 

 

However there is another problem - if I go to another window and copy any text and try to paste it in Illustrator using the system hotkey, it (text) is pasted as a separate text frame. 

Instead, you need to replace the selected characters with characters from the clipboard, but it doesn't work this way.


 

A new bug? The same scenario is working when you do it all by tools.

This topic has been closed for replies.

1 reply

Sergey Osokin
Inspiring
October 17, 2024

A workaround may help in this case. Get the content of the pasted text frame and replace it in the target text frame.

 

replace();

function replace() {
  var doc = app.activeDocument;

  if (doc.textFrames.length === 0) {
    return;
  }
  var targetTF = doc.textFrames[0];

  app.selection = null;
  app.paste();

  if (app.selection.length === 0 || app.selection[0].typename !== "TextFrame") {
    alert("No text string in the clipboard");
  } else {
    targetTF.contents = app.selection[0].contents;
  }

  app.selection[0].remove();
}