• 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: Problems Writing to a File
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems Writing to a File


  • Subject: Re: Problems Writing to a File
  • From: has <email@hidden>
  • Date: Thu, 10 Nov 2005 19:14:42 +0000

Steve Suranie wrote:

>I'm trying to write to a file but I am having some problems with my script:
>
>set theFilePath to (path to desktop) & "archiveTool:htmlFiles:tempFile.txt" as string

Concatenating an alias and a string and coercing the resulting two-item list to a string is not a particularly safe move; think TIDs. Another problem is that HFS paths cannot distinguish between identically named drives, so if you have another drive mounted with the same name then it's a crapshoot as to which one your path will refer to. A third source of potential errors is using 'as string' instead of 'as unicode text' coercions on unicode-based data: throw in some fancy 'foreign' characters and it can easily break, although that won't be the cause in your particular case since all your filesystem names are ASCII-compatible.

Anyway, here's how I'd do it, eliminating TID issues and using posix paths to avoid any drive name collisions (the redundant 'tell app "Finder"' block and 'my' keyword have also been cleaned out):

set theFileRef to POSIX file (POSIX path of (path to desktop) & "/archiveTool/htmlFiles/tempFile.txt")
set theContent to "This is a test"

writeFile(theFileRef, theContent)

--subs--

on writeFile(theFileRef, theContent)
	set f to (open for access theFileRef with write permission)
	write theContent to f
	close access f
end writeFile


HTH

has
--
http://freespace.virgin.net/hamish.sanderson/
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Problems Writing to a File
      • From: Steve Suranie <email@hidden>
  • Prev by Date: RE: Problems Writing to a File
  • Next by Date: Re: Problems Writing to a File
  • Previous by thread: Re: Problems Writing to a File
  • Next by thread: Re: Problems Writing to a File
  • Index(es):
    • Date
    • Thread