Re: When is a file open but not open?
Re: When is a file open but not open?
- Subject: Re: When is a file open but not open?
- From: "John Jones" <email@hidden>
- Date: Thu, 04 Aug 2005 16:14:09 -0400
Hi Andrew,
Thanks for your response. I had actually tried that, trap the error of trying to open an already open file and close it. The problem is that it also errors on trying to close it and reports that it's closed. That's what so perplexing. The only way I have been able to correct it is open the file in a text editor, make some change then save it. That straightens the system out but doesn't help my automated script.
John
>>> <email@hidden> 8/4/2005 3:50:43 PM >>>
Hi John,
> The problem is that occasionally the finder will get confused and think the file is open. > Is there anything I can do to force it closed?
I has a similar problem just last week. This is the script I came up with and it worked fine for me. I'm not taking any credit - the 'try - on error - end try' code came from Matt Neuburg's book (pp 344 and 345) together with gems from others on this list!
----------
global this_file
-- Create / open the file set path_name to (path to desktop) as string set file_name to path_name & "MyChangeLog.log" try set this_file to open for access file file_name with write permission on error close access file file_name display dialog ("Problem opening log file") return end try
-- Clear any existing data and write the start time try set eof this_file to 0 -- Erase file if it exists write_line("Starting at " & (current date) & return) on error close access file file_name display dialog ("Error writing to file log (1)") end try
-- Do your stuff here, probably in a loop
-- Create your log message set this_name to "MyFile.jpg" set log_message to "Done stuff with " & this_name & return set log_message to log_message & "Updated: " & "MyOtherFile.jpg" & return & "---------" & return
-- Append the log message to the file try write_line(log_message) on error close access file file_name display dialog ("Error writing to file log (2)") end try
-- End of your stuff loop
-- Write the end time and close the file try write_line("Ending at " & (current date)) close access file file_name on error close access file file_name display dialog ("Error writing to file log (2)") end try
-- This sub-routine simply writes a string to the file with a return appended on write_line(the_string) write the_string & return as string to this_file end write_line
----------------
Hope it helps,
Andrew
|
_______________________________________________
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