• 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: Shane Stanley <email@hidden>
  • Date: Mon, 18 Jul 2016 22:50:17 +1000

On 18 Jul 2016, at 10:39 PM, Mitchell L Model <email@hidden> wrote:

In a rare out-of-the box thought I realized that we were all too fixated on AppleScript, unsurprisingly given that this is the AppleScript list. The following script performs flawlessly and works whether the file exists or not:

to createNewDocument(theApplication, thePath)
do shell script "touch " & quoted form of the POSIX path of thePath
tell application theApplication to open thePath
end createNewDocument

Yes and no. You shouldn't generally pass a path to an application -- it's going to fail with any sandboxed app. Pass a file object of some sort.

And if you want to create a file then open it, there's no need to go to the overhead of launching a shell:

set fileName to "This is a test.txt"
set theFile to ((path to desktop as text) & fileName) as «class furl»
try
set fileRef to open for access theFile with write permission
close access fileRef
end try
tell application "TextEdit" to open theFile


-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
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

References: 
 >How to create a document? (From: Mitchell L Model <email@hidden>)

  • Prev by Date: How to create a document?
  • Next by Date: Re: need explanation for trivial Safari script behavior
  • Previous by thread: How to create a document?
  • Next by thread: Help for optimization of my script
  • Index(es):
    • Date
    • Thread