Re: Folder actions on mounted folders
Re: Folder actions on mounted folders
- Subject: Re: Folder actions on mounted folders
- From: David Blache <email@hidden>
- Date: Mon, 27 Nov 2000 20:25:33 -0600
on 11/27/2000 2:24 PM, email@hidden wrote:
>
So
>
I have done folder actions for a long time. Now I wanted to do a
>
network folder actions.
>
>
eg I have a computer that is watching a folder on my ASIP server and when
>
it sees a file it opens it and does other stuff as normal. Is this
>
possible or do I need to have a folder actions on the server copy it to
>
the workstation which triggers another folder actions to do the process?
>
>
I tried it a couple of ways and no actions happen.. I ask at least in
>
part because I would like to keep the action off the already busy file
>
server and because in the Apple Help it says that the action can be on a
>
remote mounted partition, just not if it can act on one.
The short answer is that due to the way AppleTalk networking works, it can't
be done with a folder action. Folder actions will not detect files added on
other machines.
I ran into this problem very recently myself. I wanted to run a folder
action on a server that would convert image files to a given format and
rename them with appropriate extensions whenever files were dropped into a
folder.
I ended up writing an Applescript application to do the job. The script
uses an idle handler to monitor the folder for file additions, and when new
files are detected, processes them. After spending a day or two working the
kinks out, it is up and running and working perfectly.
Some things I ran into that might help you out:
* Be sure to check the busy state of all files before you begin processing
them - that was the first thing that bit me.
* It was helpful to me to use an "In" folder, a "Temp Items" folder, and an
"Out" folder. Files are dropped into the "In" folder, detected by my
application, moved to the "Temp Items" folder, processed there, and then
moved to the "Out" folder when processing is complete.
* You cannot count on the existence of the Mac OS "Temporary Items" folder.
That folder is only created after a restart when applications actually use
it. To make matters worse, some installations of the Mac OS appear to not
take kindly to people messing with the Mac OS "Temporary Items" folder via
Applescript. I only ran into problems on the server machine - the script
ran perfectly on all other machines (go figure). I ended up creating my own
"Temp items" folder to get around the problems I encountered. If you find
yourself fighting trying to create (or even use) the Mac OS Temporary Items
folder, you may want to save yourself some headache and just make your own.
* The following routine is handy for logging the actions (and errors) of
your script. I use this in place of "display dialog" calls everywhere in my
script, to ensure that the script never ties up the server. Also, I wrap
all handlers in a try block, catching and logging all errors, rather than
allowing a dialog to be displayed.
-- begin script
-- call like so: my LogEntry("error: blah blah blah")
on LogEntry(someText)
try
set logFile to (gWatchFolder as text) & gLogFileName
set logRef to open for access (file logFile) with write permission
if logRef 0 then
-- this is one line
write FormatDateTime(current date) & ": " & someText & return
starting at eof to logRef
-- this is one line
close access logRef
end if
end try
end LogEntry
on FormatDateTime(theDate)
set theDate to theDate as date
set dd to text -2 thru -1 of ("0" & theDate's day)
copy theDate to tempDate
set the month of tempDate to January
set mm to text -2 thru -1 of ,
("0" & 1 + (theDate - tempDate + 1314864) div 2629728)
set yy to text -1 thru -4 of ((year of theDate) as text)
set hh to time string of theDate
return (yy & mm & dd & " @ " & hh as text)
end FormatDateTime
-- end script
I hope this helps you...
-David