Text-app help

I wandet to write a script for all my Text-apps (Text-edit, Script-editor, Text-Wrangler, Voodoo-pad, ect.) with the ability to set the title as Name (of the related front page of my text-app) accompanied with a automatic saving action. (in front window of Finder, in Desktop by default or wherever else you want)
it’s necessary to add a extension string to the save-command? Where can i find the command to add the default extension? ?(
For now does nothing, simple what it is. Sob. :**

--Test2 

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"
	try
		set y to (folder of front window) as text
	on error
		set y to desktop as text
	end try
	set the_path to (y & "Test")
	display dialog the_path
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

I can’t believe that this string of my “Test2” above -script does not work:
save i in the_path
because below works: (its the same construction, only for demonstration)

tell application "Finder" to set x to (the desktop as text)
tell application "Script Editor"
	set i to document 1
	save i in x
end tell

Help!

That will wipe out your desktop folder and replace it with a Script Editor document. :frowning:

i’ve updated my script. Now works,
a) the document gets the entire name from paragraph 1
b) the document will save itself in the front window of (open finder win or desktop, x default)

but:
c) the open front document will not recognize the path, it saves a copy with all properties -name and contents
(this behavor is not so important, but not desired)
d) it adds no default extension to the saved copy

here we go:

--Test hh  f ff       

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"
	if exists windows then
		set y to (folder of front window) as text
	else
		set y to desktop as text
	end if
	
end tell

tell application x
	activate application x
	set cl to ""
	try
		set p1 to (paragraph 1 of document 1 as text)
	on error
		set p1 to (paragraph 1 of window 1 as text)
	end try
	repeat with i from 1 to count words in p1
		set this_word to word i of p1
		if cl is "" then
			set cl to this_word & space
		else if cl ≠ i then
			set cl to cl & this_word & space
		else if cl = i then
			set cl to cl & this_word
		end if
	end repeat
	set the_path to (y & cl)
	try
		set name of document 1 to cl
		save document 1 in the_path
	on error
		set name of window 1 to cl
		save window 1 in the_path
	end try
end tell

i hope that my script has not caused data loss for you, cwtnospam. Excuse.

Get it! if someone likes this script, then leave just a comment…(add your Text-apps, and adjust the relativ save-strings)
Cheers!



--Test hh f ff 

tell application "System Events" to set x to name of every process whose frontmost is true
set x to x as text

tell application "Finder"
	try
		set y to folder of front window as text
	on error
		set y to desktop as text
	end try
end tell

set text_apps to {"Script Editor", "TextEdit"} --ect. 

if x is in text_apps then
	tell application x
		activate application x
		set cl to ""
		try
			set pg to document 1
		on error
			set pg to window 1
		end try
		tell pg
			if pg is not "" then
				set w1 to word 1 as text
				set paras to {123456789} as string
				repeat with i from 1 to count characters in paras
					set this_word to character i of paras as number
					if w1 is in paragraph this_word then
						set this_word to (this_word as number)
						repeat with i from 1 to count words in paragraph this_word
							set this_w to word i of paragraph this_word
							if cl is "" then
								set cl to this_w & space
							else if cl ≠ i then
								set cl to cl & this_w & space
							else if cl = i then
								set cl to cl & this_w
							end if
						end repeat
					end if
				end repeat
				if x = "TextEdit" then
					set the_str to "
Formatted text= rtf
Text and Pictures= rtfd
Unformatted text= txt"
					set butt to {"rtf", "rtfd", "txt"}
				else if x = "Script Editor" then
					set the_str to "
Script document= scpt
Script droplet= app
Text= applescript"
					set butt to {"scpt", "app", "applescript"}
				end if
				display dialog "Do you want to save your document as..." & return & the_str & return buttons butt default button 1 giving up after 12
				try
					set xt to the button returned of the result
					set the_path to (y & cl & "." & xt)
					save in the_path
					set name to cl
					save in the_path
				end try
			end if
		end tell
	end tell
end if