Skip to main content
Aprking
Inspiring
October 13, 2024
Question

How can I insert specified text at the current cursor position using a script in Illustrator?

  • October 13, 2024
  • 2 replies
  • 838 views

Hello everyone, I would like to ask a simple technical question about scripting in Illustrator. How can I insert specified text at the current cursor position using a script in Illustrator? Alternatively, when using the Type tool to select a portion of text, how can I use a script to replace that text with specified text?

Thank you!

This topic has been closed for replies.

2 replies

Kurt Gold
Community Expert
Community Expert
October 14, 2024

There are very good text expander applications for both Mac and Windows OS (e.g. aText or Beeftext). Mac OS even has a built-in snippet tool.

 

Probably more convenient than a script.

m1b
Community Expert
Community Expert
October 13, 2024

Hi @Aprking, I don't know the answer to the first question. I don't think we have access to mouse events via scripting. It may be possible via an elaborate (and hacky) use of Script UI, but I wouldn't get my hopes up. I think you'll need SDK for that one.

 

As for the second question, you can do something like this:

(function () {

    var myContents = 'Replacement Text';

    var doc = app.activeDocument,
        item = doc.selection;

    if ('TextRange' !== item.constructor.name)
        return alert('Please select some text and try again.');

    item.contents = myContents;
    item.select(true);

})();

- Mark

Aprking
AprkingAuthor
Inspiring
October 13, 2024

Thank you very much to @m1b  for the help, the problem has been resolved