MacMost Q&A Forum • View All Forum QuestionsAsk a Question

How To Use an Automator To Convert Text To Title Case?

I’m a new Automator user. Using Automator and a javascript action, I’m attempting to convert the selected text to a Title case in desktop WhatsApp application where the contextual menu with Transformations – capitalize doesn’t show. However, it always comes with the error and posted below. Please assist me in resolving the issue. The following is the Javascript code in detail:

Javascript Code
—————–
function run(input, parameters) {

const patternStyle = /^\w|[\s\.]\w/gm;

input = input.replace(patternStyle, element => element.toUpperCase());

return input;
}

Error While Executing
————————–
Execution Error
Error: TypeError: input.replace is not a function. (In ‘input.replace (patternStyle, element E> element.toUpperCase ())’, ‘input.replace’ is undefined)

1. I have set up as a quick action under Automator with Workflow receives current text->in any application and Input is entire selection followed by Output replaces the selected text
2. Automator has only one action and it is Run Javascript Action with the above-posted code
—–
Kishore Kumar

Comments: 2 Responses to “How To Use an Automator To Convert Text To Title Case?”

    1 month ago

    The problem is that input is an array. You need to take the first item of that array, which should be text, to make this work. So the line where you do the work should start:

    input = input[0].replace…

    Kishore Kumar
    1 month ago

    Oh my goodness!

    Thank you very much, Gary!

Leave a New Comment Related to "How To Use an Automator To Convert Text To Title Case?"

:
:
:
0/500 (500 character limit -- please state your comment succinctly and do not try to get around this limit by posting two comments)