Le 5 juin 2016 à 20:43, Yvan KOENIG < email@hidden> a écrit :
…
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
Funny feature.
Compare what we get with the script above and this edited version in which we don't explicitly ask the script to save :
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 in thePath --saving yes end tell open thePath # Now we may work as we want upon the document end tell
In both case we have a document correctly saved but in the first one we have the tool bar and the rule as in rtf files and in fact it's really an RTF file whose name ends with .txt.In the second we haven't them exactly as when the file is defined as a text one and it's really such one.
I made some complementary tests. When we don't explicitly ask to save with "saving yes", the format of the file is defined by the extension used in the name. set testFile to "This is a test.txt" and we will get a text file. set testFile to "This is a test.rtf" and we will get an RTF one.
I got this behavior with an application which is set to create new documents as RTF ones which is the factory setting .
Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) lundi 6 juin 2016 10:58:01
|