Apply Title Case to Text Anywhere Using Script Kit

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 3 years ago

Sometimes you just want to select and modify some text you have written somewhere on your system. To help you with this, Script Kit provides a getSelectedText and setSelectedText. Between these two helpers, your script and use and/or modify the text however you want.

Applying an npm tool like title-case can help when you're not entirely sure when certain words need to be capitalized. In fact, I used the title case script on the title of this lesson!

Install title-case

// Name: Title Case

import "@johnlindquist/kit"

let { titleCase } = await npm("title-case")

let selectedText = await getSelectedText()
let titleText = titleCase(selectedText)

await setSelectedText(titleText)

// This Is the Title of My Next Blog Post

John Lindquist: [0:00] Create a script called Title Case. From here, we're going to use npm package called title-case and grab the titlecase method off of that. Then from Script Kit, we can use the await getSelectedText, which will give us the selected text.

[0:20] Then we can title case the selected text, and we'll call this titleText. Then we can use the setSelectedText helper from Script Kit. We'll set the titleText.

[0:35] To test this out, we'll just say, "This Is the Title of My Next Blog Post." We'll open Script Kit from title-case. Hit Enter, and you'll see it converted the text to title case.

[0:48] This will work anywhere in your system. Like in this jist, we'll say, "This Is the Title of Another Blog Post." Select that. On title-case, hit Enter. You'll see everything go to title case.