• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to create a document?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to create a document?


  • Subject: Re: How to create a document?
  • From: Yvan KOENIG <email@hidden>
  • Date: Sun, 05 Jun 2016 20:43:06 +0200


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



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: How to create a document?
      • From: Yvan KOENIG <email@hidden>
References: 
 >Re: How to create a document? (From: Mitchell L Model <email@hidden>)
 >Re: How to create a document? (From: Yvan KOENIG <email@hidden>)
 >Re: How to create a document? (From: Bruce Robertson <email@hidden>)

  • Prev by Date: Re: How to create a document?
  • Next by Date: Re: How to create a document?
  • Previous by thread: Re: How to create a document?
  • Next by thread: Re: How to create a document?
  • Index(es):
    • Date
    • Thread