How can I tell TextEdit to save document 1?

Hello, hello,

This works fine in 10.3.9 but not working in 10.4.11:



tell application "TextEdit"
	
	make document at beginning
	
	set text of document 1 to "Trying to save this file."
	
	save document 1 in file "startup disk:TestFile.rtf" -- brings up a save-as dialog asking for a name.
	
	save document 1 in file "startup disk:TestFile.rtf" without asking -- this doesn't work either
	
end tell


Someone please clue me in.

Thanks,
icta

You need a full path. Try this.


set thePath to (path to desktop as Unicode text) & "text.txt"

tell application "TextEdit"
	make new document at beginning with properties {text:"Some text"}
	save document 1 in thePath
end tell

Hello Craig,

Thanks but it didn’t work. I used a single-line script “choose folder” to get the path, then pasted the result into the script you posted. When I ran it, I got the same result ” a save-as dialog asking for a name. Could it be a missing scripting addition?

Here’s what I ran:



set thePath to "Grandpa'sWorld-IntelQuad:Users:dg:Desktop:" & "text.txt"

tell application "TextEdit"
	make new document at end with properties {text:"Some text"}
	save document 1 in thePath
end tell


On Leopard the previous works fine. On Tiger this seems to work.


set thePath to (path to desktop as Unicode text) & "text.txt"
tell application "TextEdit"
	make new document at beginning with properties {text:"Some text"}
	close document 1 saving in thePath
end tell

Thanks Craig,

That did work. But the first method sure looks like a bug to me since my result window showed that it saved the file even though the dialog came up and it did not save the file.

It seems to only be a problem on the first save because the following works:



tell application "TextEdit"
	
	make new document at beginning with properties {text:"Some text"}
	
	close document 1 saving in file "Grandpa'sWorld-IntelQuad:Users:dg:Desktop:Text2.rtf" -- this works
	
	open file "Grandpa'sWorld-IntelQuad:Users:dg:Desktop:Text2.rtf"
	
	make new paragraph at end of document 1 with data return & "Some more text."
	
	save document 1
	
end tell


Thanks for your help.
icta