Automating Complicated Text Inserts

If you need to insert similar text into documents often, you may want to create a JavaScript (JXA) task in Automator that makes it easier. In this example, we'll look at inserting a piece of text that contains two variables, such as: (Refer to page X or report Y). The script will prompt you for the page and report, and then insert the test into the document you are working on.

Here is the text of the JXA script:

Comments: 9 Responses to “Automating Complicated Text Inserts”

    Jeff White
    7 years ago

    var pageNumber = app.displayDialog('Page Number?', {defaultAnswer:''});
    when I compile your script I get this error:
    Error on line 8: SyntaxError: Invalid character '\u8216'
    The first line of this message is line 8
    Do you know what error is?

    7 years ago

    Jeff: Make sure you don't have an extra invisible character somewhere. Not just on that line, but the next one (which is line 8 if you copied and pasted).

    Jean-Claude
    7 years ago

    What is the application you mentioned in your video?

    7 years ago

    Jean-Claude: Not sure what you mean. I am using Automator in the video. I am demonstrating the script by inserting text into Pages. If you mean something else, let me know the time in the video where I mention it and I will try to clarify.

    Jean-Claude
    7 years ago

    At approx 34 seconds in the video, you say "there are some apps you can purchase..."

    7 years ago

    Jean-Claude: Apps like TypeIt4Me and TextExpander.

    Jean-Claude
    7 years ago

    OK, thanks!

    Russell D
    7 years ago

    That is the coolest thing I have ever seen. I have been using Mac for six years and am stil learning things it can do.

    Ulrich Maasmeier
    7 years ago

    @Jean-Claude:
    There is another app for text automations: Typinator.
    I use it since textexpander went on to monthly subscriptions.
    Works great.

Comments Closed.