Le 5 juin 2016 à 19:12, Bruce Robertson < email@hidden> a écrit :
Result: a “not saved” dialog The document “This is a test.txt” could not be autosaved. Your changes will not be saved until this problem is resolved. On Jun 5, 2016, at 9:06 AM, Yvan KOENIG <email@hidden> wrote:
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
Oops. You're right … but I was right too.
I ran set testFile to "This is a test.txt" set thePath to ((path to desktop as text) & testFile) as «class furl» tell application "TextEdit" activate make new document tell document 1 set its text to "one two three" set its name to testFile close it saving yes saving in thePath end tell open thePath end tell
then I ran
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
and it behaved flawlessly.
I just repeated the described scheme with the same result. It's just when I ran the second script one more time that I got the described error. So, at last, it seems that the correct scheme is the script which saves during the closing process and reopen the file immediately. We may strip it a bit:
set testFile to "This is a test.txt" set thePath to ((path to desktop as text) & testFile) as «class furl» tell application "TextEdit" activate make new document tell document 1 close it saving yes saving in thePath end tell open thePath # Now we may work as we want upon the document end tell
Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) dimanche 5 juin 2016 20:39:06
|