• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Script Debugger Substitutions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Script Debugger Substitutions


  • Subject: Script Debugger Substitutions
  • From: Christopher Stone <email@hidden>
  • Date: Tue, 11 Sep 2012 03:38:54 -0500

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

------------------------------------------------------------------------------------------------
#       Author: Christopher Stone <email@hidden>
#      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
------------------------------------------------------------------------------------------------

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Script Debugger 5: Duplicate Selection Handler
  • Next by Date: Rewrite simple Finder tell statement to "do shell script"
  • Previous by thread: Re: Script Debugger 5: Select Current Line (was Duplicate Selection Handler)
  • Next by thread: Rewrite simple Finder tell statement to "do shell script"
  • Index(es):
    • Date
    • Thread