• 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: When is a file open but not open?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: When is a file open but not open?


  • Subject: Re: When is a file open but not open?
  • From: Paul Berkowitz <email@hidden>
  • Date: Thu, 04 Aug 2005 13:11:47 -0700
  • Thread-topic: When is a file open but not open?

Title: Re: When is a file open but not open?
If there's really a problem in simply  trying to 'open for access' (it might not be a 'with write permission' problem due to an open file, but rather to NO permissions in that directory), there's a possibility that then trying to 'close access' in the error block will itself error. So you're probably better doing:

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
        try
            close access file file_name
        end try
        display dialog ("Problem opening log file")
        return
end try


and the same in the other similar parts of the script.


--
Paul Berkowitz



From: <email@hidden>
Date: Thu, 4 Aug 2005 20:50:43 +0100
To: <email@hidden>
Cc: John Jones <email@hidden>
Subject: Re: When is a file open but not open?


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
 _______________________________________________
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

References: 
 >Re: When is a file open but not open? (From: email@hidden)

  • Prev by Date: Re: Default Email App
  • Next by Date: Re: When is a file open but not open?
  • Previous by thread: Re: When is a file open but not open?
  • Next by thread: Re: When is a file open but not open?
  • Index(es):
    • Date
    • Thread