Automatic title and save

Hi,
i wrote a script for the Script Editor, which tracks the first line of
my front document (like --Test 1) and converts :

a) the first line in the title of front document and…
b) asks me where to save this document (in front win of Finder -else
the Desktop-folder if no win are open or in the path of window x of a
open Applescript-window)

now, i asked myself if there is a way to write a similary script for every texteditor -based application?
The first problem is that it will not want to save the file, the second to find the info of first line, which is less difficulty, i thing. Ideas? :expressionless:

--Test 1 

tell application "System Events" 
        set x to name of every process whose frontmost is true 
        set x to x as text 
end tell 
tell application "Finder" 
        set y to (folder of front window) as text 
        set the_path to (y & "Test 1") 
end tell 

tell application x 
        activate application x 
        try 
                set i to window 1 
        on error 
                set i to document 1 
        end try 
        try 
                save i in the_path 
        on error the error_message number the error_number 
                display dialog "Error: " & the error_number & ". " & the 
error_message buttons {"Cancel"} default button 1 
        end try 
end tell

Ciao!