Hey Folks,
I'm a big fan of text-substitution and have been using utilities to provide this labor saving feature since TypeIt4Me first came out more than 20 years ago.
These days I'm using Typinator, because its smart quick-search function just makes it easier to find what I'm looking for amongst thousands of clippings.
I also use the hell out of Script Debugger's built-in text-sub-function, because it has intelligent features beyond simple substitution.
However. Sometimes I want to do some quick and dirty subs and don't want to save them for posterity in either Typinator or Script Debugger.
The character range of the selection-object makes this easy to accomplish.
This script is also very new, only lightly tested, and undoubtably will undergo further refinement. Presently it only handles word-to-phrase substitutions, but it will be easy to modify to handle more complex structures.
The _subs property items must be separated by tabs.
Bind it to a keyboard shortcut in the SD script menu and go to town.
-- Best Regards, Chris
------------------------------------------------------------------------------------------------ # Created: 2012-09-11 : 02:05 # Modified: 2012-09-11 : 02:58 # Application: Script Debugger # Purpose: Substitute expressions for the selected word or word to the left of the cursor. # Dependencies: None: OSX components only. ------------------------------------------------------------------------------------------------ property _subs : quoted form of "
simple VERY COMPLEX! silly Quite Serious!
" tell application "Script Debugger" tell document 1 set _range to character range of selection set _cursor to item 1 of _range
if item 2 of _range = 0 then set _text to text 1 thru (_cursor - 1) of (get source text) set _len to length of (last word of _text) set _cursor to _cursor - _len set _range to {_cursor, _len} set selection to _range set sel to selection else set sel to selection end if
set regEx to ("^" & sel) set _repl to do shell script "awk -F'\\t+' '/" & regEx & "/ { print $2 }' <<< " & _subs
if _repl ≠ "" then set _len to length of _repl set selection to _repl set selection to {_cursor, _len} else beep end if
end tell end tell ------------------------------------------------------------------------------------------------
|