select function and go directly to reference.elgg.org with AppleScript

Hello,

I write a little code to go directly to the manual of the elgg function I have selected in my favorite editor.

This is an applescript code you can use everywhere with fastscripts or in BBedit for example... Enjoy !

tell application "BBEdit"
    -- get selection
    set Laselection to selection as string
   
    -- skip bad character like ' & ( ) /
    set thecommandstring to "echo \"" & Laselection & "\" | sed \"s/[!=\\/'\\$\\(\\) ]//g\"" as string
    set Laselection to do shell script thecommandstring
   
    -- get first char and get his ASCII
    set c to character 1 of Laselection
    set the ASCII_num to (the ASCII number c)
    if ASCII_num ≥ 65 and ASCII_num ≤ 90 then set ASCII_num to ASCII_num + 32
    set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"}
    set x to item ((ASCII_num div 16) + 1) of the hex_list
    set y to item ((ASCII_num mod 16) + 1) of the hex_list
    set c to (x & y) as string
   
    -- search link
    set thecommandstring to "curl http://reference.elgg.org/search/all_" & c & ".html | grep " & Laselection & " | sed -e 's/.*href=\"...//;s/\" target.*//'" as string
    set Lelien to do shell script thecommandstring
   
    -- and go
    set theURL to "open -a Firefox http://reference.elgg.org/" & Lelien
    do shell script theURL
end tell