Insert and Close Tag Script for BBEdit


/ Published in: AppleScript
Save to your folder(s)

I've used Textmate since I started hand-coding websites. My boss loves BBEdit. This script allows me to do the thing I missed most from Textmate creating and wrapping tags around text. Enjoy!


Copy this code and paste it in your HTML
  1. tell application "BBEdit"
  2. set theText to text of front text document
  3. set theSelection to the selection as string
  4. set theCharStart to (characterOffset of selection)
  5. set theResponse to text returned of (display dialog "Wrap what tags around selection?" default answer "" default button 2)
  6. set theTag to first word of theResponse
  7. --set theOther to chars((length of first word of theResponse) - end) of theResponse
  8. set tmpStr to "<" & theResponse & ">" & theSelection & "</" & theTag & ">"
  9. set the selection to tmpStr
  10. set insertionPosition to (theCharStart + (length of tmpStr))
  11. --select (characters insertionPosition through (insertionPosition - 1)) of front text document
  12. select insertion point before character insertionPosition of front text document
  13. end tell

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.