Re: Finder scripts and writing logs
Re: Finder scripts and writing logs
- Subject: Re: Finder scripts and writing logs
- From: Gary Lists <email@hidden>
- Date: Thu, 29 May 2003 23:22:59 -0400
On or about 5/29/03 6:56 PM, Mike Rowland wrote:
>
Hello all.
>
>
I consider myself a decent scripter and find myself ready to kill some four
>
legged animal over my frustration with trying to write a log file entry..
>
>
>
Here is my issue.
>
>
I have some os 9 scripts which move postscript files around and help direct
>
traffic for a prepress operation. They change the name (for future process
>
initiation) and copy the files to a server. A log file and or entry is also
>
generated for the transaction for tracking purposes.
>
>
I have set two properties thepath and thelog. I want to open for access file
>
(alias (thepath&thelog as text)) with write permission, then write an entry
>
and close the log. I get a message that file document file thelog of folder
>
x of folder y of disk z can not be made into a file....
>
>
Any ideas and the script works a charm in os 9.2.2
>
>
Mike
Here is the write file sub-routine I have been using for a few months. The
issue for me (also frustrating) was making sure all the references to the
file object were parallel.
It takes a bit to get alias "..." and file "..." and plain ole "..."
straight.
In this sub-routine, 'passedFile' is the name of the file in the Finder. It
will take either alias|file|text (it coerces to text for standardization,
then uses file "..." .)
So you can say:
writeToFile(mystring,"output_file.txt",true)
or
writeToFile(mystring,alias "HD:Desktop:output_file.txt", false)
I just drag and drop my clipping file into any script that I need a write
handler and I haven't had any problems.
The initial try block is not mine, but I don't know where I got it. I only
added the suggested on error ... try ... to make sure the file gets closed.
-- ======================================================
-- write to a file with either appending or replacing
-- ======================================================
on writeToFile(thisChunk, passedFile, appendBoolean)
try
set wFile to the passedFile as text
set the openFile to open for access file wFile with write permission
if appendBoolean is false then set eof of the openFile to 0
write thisChunk to the openFile starting at eof
close access the openFile
return true
on error
try
close access file wFile
end try
return false
display dialog ("File could not be written. It may already be open.
Close the file, or rename it, then try again.")
end try
end writeToFile
-- ======================================================
HTH
--
Gary
Please reply directly to the list.
Incoming messages are auto-deleted. (It's anti-spam, that's all.)
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.