Saving as Text File

I have the script:


set soundLocation to (choose file name default name "example.aiff")
set theText to "Hello"
say theText saving to soundLocation

How can I make this script have

theText

be saved as a plain text file.

If you’d searched a bit, you’d have found this.

set Filename to "TestFile" --Name the file

set this_data to "The quick brown fox jumped over the lazy dog" & return as string --Any text here
set target_file to ((path to desktop as Unicode text) & Filename) --You can eliminate "Filename" as a variable and type the filename as part of the path (if you wish) but you need a full path
set append_data to true --Set this to false if you want to overwrite, true if you want to add text to an existing file

try --This part writes the file
	set the target_file to the target_file as text
	set the open_target_file to open for access file target_file with write permission
	if append_data is false then set eof of the open_target_file to 0
	write this_data to the open_target_file starting at eof
	close access the open_target_file
on error
	try
		close access file target_file
	end try
end try

--This is optional to set the font
tell application "TextEdit"
	open target_file as alias
	tell paragraphs of the text of the front document
		set the font to "Arial"
		set the size to 16
	end tell
end tell

Saving text to a file needs just a bit more code than above, Simon. However, in an effort to keep things almost as simple as your original:

to saveText from t to f
	set o to open for access f with write permission
	set eof o to 0
	write t to o
	close access o
end saveText

set textLocation to choose file name default name "example.txt"
set theText to "Goodbye"
saveText from theText to textLocation