Page 1 of 1

Reversing Character

Posted: 2011-03-03 07:57:58
by bjast
Has anyone ever developed a macro that reverses characters?

For example:

theer > there

whele > wheel

ohlding > holding

As I've gotten older I'm finding I'm making this kind of mistake more often.

Thansk

Re: Reversing Character

Posted: 2011-03-03 10:23:33
by Kino
bjast wrote:As I've gotten older I'm finding I'm making this kind of mistake more often.
Same here ;-( Or worse: it is getting harder and harder for me to detect typos.

In the past, a similar problem was discussed at:
http://www.nisus.com/forum/viewtopic.php?f=17&t=2659
To sum up, if you want to swap a character before the insertion point with a character after it, just hit control-t which is a built-in Cocoa keybinding, working in all Cocoa applications. However, if you want to reverse two characters before the insertion point, you need something else.

Here is yet another macro attempt for the latter case, the laziest one ;-)

Code: Select all

Send Selector 'moveBackward:'
Send Selector 'transpose:'
As the macro above just call Cocoa actions via Send Selector command, it is easy to enable the same functionality in all Cocoa applications by putting a custom keybindings dictionary (DefaultKeyBinding.dict) in /Users/you/Library/KeyBindings/. Attached is a sample dictionary file. It is a text file you can edit, for example, in TextEdit.

Code: Select all

{
	"^'" = (
		"moveBackward:",
		"transpose:"
	);
}
"^'" defines the key combination (control-') assigned to this functionality. To execute it by another key combination, just change "^'":

Code: Select all

^: control key
$: shift key
@: command key
~: option key
For example, "^a" for control-a, "^$n" for control-shift-n.
DefaultKeyBinding.dict.zip
(640 Bytes) Downloaded 238 times