Problems with Save Dialog in TextEdit

Thanks for help …

I use this


set inputfolder to (choose folder)
tell application "Finder" to set thefiles to files of inputfolder

repeat with ttt in thefiles
	activate application "TextEdit"
	tell application "System Events"
		tell process "textedit"
			keystroke "T" using {command down, shift down}
			keystroke return
			keystroke "S" using {command down}
		end tell
	end tell
end repeat


but as it get to

“keystroke “S” using {command down}”

textedit opens a dialog asking me the file location

and the repeat function ends

how can repeat the whole process in the folder?

Hi,

keystroke “S” using {command down} is equal to keystroke “s” using {command down, shift down}

use the lowercase letter to get the ⌘S command

Thanks for your suggestion but I now find this problem:

if I use the script just on an open TextEdit document, System Events will convert from RTF to TXT
yet it will not save the file no matter which Keystroke i invoke

using the Repeat option
it will not do anything at all

in other words the original folder will keep all files as they were before using the script

How can I solve this problem?

Thanks a lot

Use the save option of textedit and not doing this with ui element scripting.

tell application "TextEdit"
	set allDocs to a reference to every document
	repeat with thisDoc in allDocs
		if (path of (properties of thisDoc as record)) is not missing value then --the document is not new
			tell thisDoc to save
		else
			--the document is new so we save it into a new file
			tell thisDoc to save in file ((path to desktop folder) & name of thisDoc & ".rtfd" as string)
		end if
	end repeat
end tell

Thanks all for your help but probably I should rephrase my question:

I have a folder with several .RTF file.
I hope to convert the files to standard TXT
this is possible in a TEXTEDIT open document choosing the
FORMAT->MAKE PLAIN TEXT menu
using Applescript

tell application “System Events”
tell process “textedit”
keystroke “T” using {command down, shift down}
keystroke return

the RTF file will become PLAIN TEXT

however I hope to be able to select a folder where these files
select them one by one and use the above scrip.
what I miss is the Save part.
If I add to the previous part of the script

keystroke “s”

TextEdit opens a Dialogue asking me where I want to save the file and if I want to change the name-

Is there a way to evoke a “save function” in System Events using the “process TextEdit” so the file already converted to PLAIN TEXT closes?

This because I have several hundred file and a repeat function will be a great help.
This is my original script which


set inputfolder to (choose folder)
tell application "Finder" to set thefiles to files of inputfolder

repeat with ttt in thefiles
   activate application "TextEdit"
   tell application "System Events"
       tell process "textedit"
           keystroke "T" using {command down, shift down}
           keystroke return
           keystroke "s"
       end tell
   end tell
end repeat

Once every file is processed I must manually allow to save changes for the files.
TextEdit asks for each file if I want to save the changes or not.

Is there something like

"keystroke “W"saving yes” I could use in my script?

this function exists in Textwrangler but unfortunately this software doesn’t read RTF files …

Thanks again

forget TextEdit, the shell command textutil can do this much easier


set inputfolder to (choose folder)
tell application "Finder" to set thefiles to files of inputfolder

repeat with ttt in thefiles
	do shell script "textutil -convert txt -encoding UTF-8 " & quoted form of POSIX path of (ttt as text) -- convert rtf to txt
end repeat

Thanks it works perfectly

Danny