Skip to main content
Aprking
Inspiring
Oct 13, 2024 9:35 AM UTC
Question

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

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 is closed to new replies. Start a new post to keep the conversation going.

7 replies

Kurt Gold
Community Expert
Community Expert
Oct 14, 2024 6:13 PM UTC

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.

Translate
m1b
Community Expert
Community Expert
Oct 13, 2024 9:50 AM UTC

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

Translate
Aprking
AprkingAuthor
Inspiring
Oct 13, 2024 1:31 PM UTC

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

Translate