Oops ! One comment was misplaced. Better with : tell application "TextEdit" activate set doc to make new document log doc --> (*document Sans titre*) set the name of doc to "Test17" log doc -- (*document Sans titre*) try set the text of doc to "1" --> set every text of document "Sans titre" to "1" on error errMsg number errNbr log errMsg (*Erreur dans TextEdit : Il est impossible de régler document "Sans titre" à "1".*) end try set doc to document 1 log doc --> (*document Test17*) set the text of doc to "1" --> set every text of document "Test17" to "1" end tell
Here is a more efficient scheme.
set testFile to "This is a test.txt" --set thePath to (path to desktop as text) & testFile --set posixPath to POSIX path of thePath set posixPath to POSIX path of ((path to desktop as text) & testFile) tell application "TextEdit" activate --make new document with properties {path: posixPath} # BEURK , it set the window name but doesn't set the fileName. --make new document with properties {path: posixPath, name:testFile} # BEURK, it behaves the same ! make new document with properties {path:posixPath} # doesn't set the fileName but correctly set the path tell document 1 set its text to "one two three" set its name to testFile # no need to save here, AutoSave did the job ! end tell end tell
I left two disabled make to describe different behaviors.
Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) dimanche 5 juin 2016 18:04:28
|