Adding Items Delay
Adding Items Delay
- Subject: Adding Items Delay
- From: John Futhey <email@hidden>
- Date: Fri, 20 Jul 2001 20:48:23 +0000
I have a watched folder script that kicks into gear when items are added to
a folder. It copies items to another folder inside this folder as soon as
they are added.
Because this folder is on a server, users are waiting for these added files
so they can open them and alter them. As soon as they see them, they are
grabbing them before the script has a chance to copy them. Thus the script
says the file is busy when it attempts to copy it. Is there a way to copy
them immediately so that users can't pre-empt the script?
Thanks in advance for any help.
Here is the script:
property copy_checks_indicator : true
property item_check_delay_time : 0.01
property folder_check_delay_time : 0.01
property special_label_index : 7
on +event facofget; this_folder given +class flst;:added_items
if the copy_checks_indicator is true then
set the added_items to my check_added_items(the added_items)
if the added_items is {} then return "no vaild items"
end if
-- copy items to internal folder
repeat with i from 1 to the number of items in added_items
set the_file to item i of added_items
tell application "Finder"
if (file the_file exists) then
try
copy file the_file to folder "BLAHBLAH" of this_folder
set the label index of the_file to the 0
on error
end try
end if
end tell
end repeat
end +event facofget;
on check_added_items(the added_items)
-- check the transfer status of every added file to determine
-- if each file has completed being moved into the attached folder
set the notbusy_items to {}
repeat with i from 1 to the number of items in the added_items
set this_item to (item i of the added_items)
if my check_busy_status(this_item) is false then
set the end of the notbusy_items to this_item
end if
end repeat
return the notbusy_items
end check_added_items
on check_busy_status(this_item)
if the last character of (this_item as text) is ":" then
set the check_flag to false
repeat
tell application "Finder"
try
set the busy_items to the name of every file of the
entire contents of this_item ,
whose file type begins with "bzy"
on error
set the busy_items to {}
end try
end tell
if the check_flag is true and the busy_items is {} then return
false
+event sysodela; the folder_check_delay_time
set the check_flag to true
end repeat
else
tell application "Finder"
if (the label index of this_item) as integer is the
special_label_index then
return "ignore"
end if
end tell
set the check_flag to false
repeat
tell application "Finder"
set the item_file_type to the file type of this_item
end tell
if the check_flag is true and ,
the item_file_type does not start with "bzy" then
tell application "Finder"
set the label index of this_item to the
special_label_index
end tell
+event sysodela; the item_check_delay_time
return false
else if the item_file_type does not start with "bzy" then
set the check_flag to true
end if
+event sysodela; the item_check_delay_time
end repeat
end if
end check_busy_status