Jump to content

Can Alfred Do This? Change the keyboard input source for selected text?


Recommended Posts

I'm using multiple input sources (languages) for editing documents.  I often have typed half of a sentence with the wrong language, only to have to delete the text, switch languages (easy enough) and then retype it.  Not a big deal if this just happens once or twice.  But I do this ALL the time.  I've found a few apps that will do this, but for some reason they only work for particular languages, and seem to have been native Windows apps first, so their Mac apps seem a bit odd.  Punto Switch, Keyboard Ninja, OverLang are some of them.  A Redditor has Punto Switcher working fine within Windows, but on Mac I'm not able to have it switch any other input source besides Russian.  I'm switching between English, Greek, and Khmer.

 

I'd LOVE to just select the text, smash a keyboard shortcut, and have the text converted and the input source changed.  I can do this, but several shortcuts, instead of just one.

 

Any thoughts on if this is something Alfred can handle?  I've not dabbled in workflows much (but use Alfred all day!)

 

Thanks.

 

Link to comment

You could probably do this via a script assigned to a keyboard shortcut.
 
If I were trying to do this, I'd do it in four steps:

  • Use AppleScript to send the key presses ⌘⇧←  then ⌘X to select the current line and cut the text to the pasteboard.
  • Use a custom script to replace the characters in the cut text with the characters on the same keys when the target keyboard layout is selected, e.g. going from an English layout to a German one, that would mean replacing "y" with "z" and ";" with "ö".
  • Paste the altered text (also using AppleScript).
  • Use this script to switch to the desired input source.

For use outside Alfred, I guess you'd want to skip the ⌘⇧← bit and select the text yourself.

Link to comment
  • 1 year later...

I made an apple script which switches russian to english and english to russian languages. 

 

https://github.com/j2thex/keyboard-language-switcher

 

I use alt+shift+z to switch. So when i misytped a couple of words - i press alt+shift+left and then alt+shift+z 

 

The script is not perfect, but it's something, a viable alternative to punto switcher

 

Please help fix bugs

Edited by j2thex
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...