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 2 years ago
Updated 2 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.

egghead
egghead
~ 29 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today