Re: Problems Writing to a File
Re: Problems Writing to a File
- Subject: Re: Problems Writing to a File
- From: Steve Suranie <email@hidden>
- Date: Thu, 10 Nov 2005 14:59:17 -0500
- Thread-topic: Problems Writing to a File
Thanks for all the tips and advice folks. I rebooted my machine and the
original script (see below) worked fine. But I will take into consideration
some of the things pointed out here.
--set theFilePath to choose file with prompt "Choose a File"
set desktopFolder to (path to desktop)
set theFilePath to desktopFolder & "archiveTool:htmlFiles:tempFile.txt" as
string
set theContent to "This is a test"
my writeFile(theFilePath, theContent)
return theFilePath
--subs--
on writeFile(theFilePath, theContent)
set f to (open for access theFilePath with write permission)
write theContent to f
close access f
end writeFile
On 11/10/05 2:14 PM, "has" <email@hidden> wrote:
> 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
_______________________________________________
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