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: 3 Responses to “How To Use an Automator To Convert Text To Title Case?”

    4 years 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
    4 years ago

    Oh my goodness!

    Thank you very much, Gary!

    Randall Reetz
    3 years ago

    This works great UNLESS there are non-alphabetical chars in the string to be converted. In my case, invisible chars stop the script, as does "(" and ")" parenthasis chars.

Comments Closed.