On Jul 28, 2011, at 5:46 PM, Brian Christmas wrote: For a start, TextEdit no longer allied files to be save under the .txt name extension.
Well, actually it will.
You cannot save a rich-text document with a .txt name extension. To get a .txt extension, you have to save it as plain text.
If you specify a format, TextEdit insists that you also supply a destination filename. It's dictionary, however, lies. It says the destination must be an alias. That can't be right; you can only have an alias to an existing item, and you probably want to save to a new file.
Oddly enough, what it really wants is a POSIX path. (The clue is that "path of document 1" returns a POSIX path.)
set itsFldr to (path to documents folder as text) & "Unimportant_:" set itsName to "TEDoc4.txt" tell application "TextEdit" save document 1 as "public.plain-text" in POSIX path of (itsFldr & itsName) end tell
This is really a "save a copy…" operation. If the document was unsaved in TextEdit, it still is. If it has been saved, it's still based on that file.
I couldn't find a way (short of UI scripting) to convert the front document to Plain Text. Even with UI scripting, I couldn't find a way to find out the document's current format, so there's no way to know if you have to simulate a command-shift-T to switch formats or not. If the document has already been saved, you could look at it's path and get the extension from that, but if it hasn't been saved the path is still "missing value".
I suppose you could tell TextEdit to close document 1 without saving, and then re-open the .txt file you just saved. |