4

I am looking for a Chrome extension that can, with a keyboard shortcut, convert text to Sentence case and vice versa.

For example:

.THIS IS A SAMPLE TEXT

should be converted to

.This is a sample text

Requirements:

  • Keeps letter after . as a capital (for a sentence)
  • Keyboard shortcut
  • Works in website textboxes/textareas etc.
  • Works on Chrome in Windows 7 and OSX 10.6.8

NOTE: I am not looking for this to convert the text in the clipboard. I am looking for a solution that works with the selected text inside a textbox/textarea in a website.

  • Are you wanting that for text you copy out of browser or for text displayed in the browser? – Nick Dickinson-Wilde Jul 4 '14 at 16:18
  • 1
    Also it sounds to me that you want Sentence Case rather than strictly speaking lower case - not that it matters a lot but they are slightly different. – Nick Dickinson-Wilde Jul 4 '14 at 16:18
  • @NickWilde Ahhh... OK, I didn't know the term 'Sentence case' was actually real! – ᔕᖺᘎᕊ Jul 4 '14 at 16:21
  • @NickWilde And, for text selected in the browser, that's it – ᔕᖺᘎᕊ Jul 4 '14 at 16:40
2

A script to do it with AutoHotkey (scripting language for desktop automation on Windows), in case it's ok not to be browser only:

CTL+ALT+k - Sentence case (what you asked for)
CTL+L - convert to lowercase
CTL+U - convert to uppercase
CTL+K - invert the case (e.g. "The Big Dog" becomes "tHE bIG dOG")
SHIFT+CTL+K - convert to capitalized (e.g. "the big dog" becomes "The Big Dog")
SHIFT+CTL+U - convert to sentence case

Code:

!^k::                                           ; Sentence case
StringLower, Clipboard, Clipboard
Clipboard := RegExReplace(Clipboard, "((?:^|[.!?]\s+)[a-z])", "$u1")
Send %Clipboard%
RETURN

^u::                                                                 ; Convert text to upper
 StringUpper Clipboard, Clipboard
 Send %Clipboard%
RETURN

^l::                                                                 ; Convert text to lower
 StringLower Clipboard, Clipboard
 Send %Clipboard%
RETURN

+^k::                                                                ; Convert text to capitalized
 StringUpper Clipboard, Clipboard, T
 Send %Clipboard%
RETURN

^k::                                                                 ; Convert text to inverted
 Lab_Invert_Char_Out:= ""
 Loop % Strlen(Clipboard) {
    Lab_Invert_Char:= Substr(Clipboard, A_Index, 1)
    if Lab_Invert_Char is upper
       Lab_Invert_Char_Out:= Lab_Invert_Char_Out Chr(Asc(Lab_Invert_Char) + 32)
    else if Lab_Invert_Char is lower
       Lab_Invert_Char_Out:= Lab_Invert_Char_Out Chr(Asc(Lab_Invert_Char) - 32)
    else
       Lab_Invert_Char_Out:= Lab_Invert_Char_Out Lab_Invert_Char
 }
 Send %Lab_Invert_Char_Out%
RETURN

Example:

  • dvfv dKMLM sdf. sdf SDFKLMSF sdf. -> Dvfv dkmlm sdf. Sdf sdfklmsf sdf.
| improve this answer | |
  • Does this convert the clipboard text? I didn't mean that, sorry. I want to have a way to convert the text inside a textbox/textfield on a website... – ᔕᖺᘎᕊ Jul 4 '14 at 16:46
  • @shub In this case adding a few more commands in the AHK script should do the trick. autohotkey.com/docs/commands/Send.htm – Franck Dernoncourt Jul 4 '14 at 16:51
0

Building on Franck's AutoHotKey answer, mostly from here, is this script:

#d:: ConvertSentence()

ConvertSentence()
{
    clipSave := Clipboard
    Clipboard = ; Empty the clipboard so that ClipWait has something to detect
    SendInput, ^c ;copies selected text
    ClipWait
    StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
    StringLower, Clipboard, Clipboard ;Convert case
    Clipboard := RegExReplace(Clipboard, "(((^|([.!?]+\s+))[a-z])| i | i')", "$u1")
    Len:= Strlen(Clipboard) ;Set number of characters
    Send %Clipboard% ;Send new string
    Send +{left %Len%} ;Re-select text
    VarSetCapacity(OutputText, 0) ;free memory
    Clipboard := clipSave ;Restore previous clipboard
}

When you press Windows + D, the selected text will be converted to Sentence case.

Unfortunately AutoHotKey is only for Windows, so this won't work on Chrome on all platforms!

| improve this answer | |
  • it works by copying the selected text, converting the copied text, pasting the converted text, and clearing the clipboard afterwards. – ᔕᖺᘎᕊ Jul 21 '14 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.