RunFromTextWrangler or RunFromBBEdit ?

108 views
Skip to first unread message

Fabio Vitali

unread,
Feb 5, 2014, 12:02:20 PM2/5/14
to textwr...@googlegroups.com
Hello. 

I was trying to create an Applescript text filter to wrap text within custom HTML tags. 


"When you apply such an item, TextWrangler will pass either the selected text (or the contents of the active document, if there is no selection) as a reference to a ‘RunFromTextWrangler’ entry point within your AppleScript, and your script should return a string which TextWrangler will use to replace the selected text (or the contents of the document).", 

so I took a BBEdit script from http://bbedit-hints.tumblr.com/post/41277831904/example-of-how-to-create-a-bbedit-text-filter-with and change it so that it looks like the following: 

on RunFromTextWrangler(myRange)
set myText to myRange as string
set tag to text returned of (display dialog "Insert tag and attributes without < e >" default answer "span class='main'")
set output to "<" & tag & ">" & myText & "</" & first word of tag & ">"
return output
end RunFromTextWrangler

put it in the Text Filters folder and tried it. Did not work with error: "This Apple Event was unknown to the recipient and could not be processed (MacOS Error code: -1708)" which seems to mean "the AppleEvent was not handled by any handler". 

Then I changed back to RunFromBBEdit, and IT WORKS!

on RunFromBBEdit(myRange)
set myText to myRange as string
set tag to text returned of (display dialog "Insert tag and attributes without < e >" default answer "span class='main'")
set output to "<" & tag & ">" & myText & "</" & first word of tag & ">"
return output
end RunFromBBEdit

So I assume that the TextWrangler manual was obtained automatically from a similar BBEdit manual, but the handler is RunFromBBEdit anyway. I believe the documentation should be updated.  

regards

Fabio

Christopher Stone

unread,
Feb 6, 2014, 1:36:50 AM2/6/14
to TextWrangler-Talk
On Feb 05, 2014, at 11:02, Fabio Vitali <fvi...@gmail.com> wrote:
I was trying to create an Applescript text filter to wrap text within custom HTML tags. 
Did not work with error: "This Apple Event was unknown to the recipient and could not be processed (MacOS Error code: -1708)" which seems to mean "the AppleEvent was not handled by any handler". 
______________________________________________________________________

Hey Fabio,

Good catch!

Please be sure to make a formal bug report to: Bare Bones Software <sup...@barebones.com>

You may be interested in this:


Ordinarily I would not make a text-filter using Applescript.  The form is more constrained than running an Applescript from the script-menu.

I would do something more like this:

-------------------------------------------------------------------------------------------

try

  

  tell application "TextWrangler"
    if front text document exists then
      tell front text document's text
        set myText to selection
        set tag to text returned of (display dialog "Insert tag and attributes without < e >" default answer "span class='main'")
        set selection's text to "<" & tag & ">" & myText & "</" & first word of tag & ">"
      end tell
    end if
  end tell

  

on error e number n
  set e to e & return & return & "Num: " & n
  tell me to set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
  if button returned of dDlg = "Copy" then set the clipboard to e
end try

-------------------------------------------------------------------------------------------

Minor changes are made to your original script in order to explicitly address the selection in the front text document and basic error-checking is added.

--
Best Regards,
Chris

Reply all
Reply to author
Forward
0 new messages