folder actions become automatically disabled

Hi all,

I just wrote a simple script to attach to a network folder, which would, upon receiving a file, copy it to a folder on my desktop depending on the creator type (in this case “??mv”). It works fine, except for when two files show up in this network folder within a few seconds of eachother, and when that happens, the script stops working and folder actions become automatically disabled. Other scripts that I have made would basically “queue” up operations that are pending (done with OS 8.6). Now I am on OS X and it seems that the script cannot handle queueing up a folder action. Any ideas?

Here is the code:


on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		activate
		beep
		repeat with this_item in these_items
			delay 15
			try
				if creator type of this_item is "??mv" then
				else
					copy this_item to folder "in" of folder "DISTILLER" of desktop
				end if
			on error errn
				display dialog errn
			end try
		end repeat
	end tell
end adding folder items to

Thanks!

It sounds like System Events (which is responsible for Folder Actions) is crashing due to a buggy script. Use Process Viewer (Jaguar) or Activity Monitor (Panther) to check to see if System Events is still running after Folder Actions quit working. If it isn’t, the script likely needs further debugging.

During debugging, you can launch System Events with: tell application “System Events” to launch

– Rob

I had tried watching the activity monitor before i put this post up, and it
did not help out very much. I cannot understand how my script is buggy,
since it is very straightforward using a simple copy command.
I honestly cannot think of another way to write this script which would make
it less buggy. Does anyone see any issues with the syntax at all? I cant.
Thanks for the help!

Try replacing the “copy” command with “duplicate”.

– Rob

I’m am going to retry the script with the “duplicate” command like you suggested.
I do remember Applescript giving me a few problems with the “copy” command.
Maybe I’m making the mistake of not putting “FILE” before my variable “this_file”??

Someone once suggested wrapping “WITH TIMEOUT OF 10000 SECONDS” and “END TIMEOUT” around the script. I’m not too sure what that does…I don’t want the script to hang for 10000 seconds if there’s a problem…

I’m also thinking of replacing the “DELAY” command and trying to put the IsBusy command.
Shown below is what I found from another post regarding IsBusy. I have NO IDEA how to add this to my script, though…has anyone ever used this before?

Thanks again for your help!

(* 
isBusy 
Checks if you can write to a file or not (if it is opened for access by other process). 

Parameters: 
f: file path, alias, posix path 

Example: 
isBusy("path:to:file.txt") --> false 
*) 

to isBusy(f) 
   set f to f as Unicode text 
   if f does not contain ":" then set f to POSIX file f as Unicode text 
    
   if busy status of (info for alias f) then return true 
    
   --> but some times this is not good enough 
   try 
      open for access file f with write permission 
      close access result 
      return false 
   on error 
      return true 
   end try 
end isBusy

ryan, as for the isBusy() script, check out this thread

http://bbs.applescript.net/viewtopic.php?t=9632

As for the folder action becoming automatically disabled, I am seeing the same thing. I am using the script isDone() that is referenced in the thread above, which in turn relies on the isBusy() code

So something is probably buggy with isBusy() that causes Folder actions to be automatically disabled under certain circumstances.

However, I am an Applescript novice, my debugging technique is surrounding statements with “display dialog…” in Script Editor… totally unsuitable to hunt this bug down

(how can you properly debug a folder action script in Script Editor anyway?!)

so hopefully someone knowledgeable can have a look at this

One way to do this is to remove the folder action handler and replace it with a “choose folder” dialog. For instance, if you use the following in the folder action…

on adding folder items to this_folder after receiving added_items
	-- do stuff when items added to folder
end adding folder items to

do this for the purpose of debugging…

set this_folder to choose folder
set added_items to list folder this_folder

-- insert your code which deals with added_items

This allows you to debug the main code before converting it to a folder action.

– Rob

Hi again all, and thanks for all the help so far…

The script is working right now, and processing files as they come in (I couldn’t get the IsBusy script to work, so I set a delay of 55 seconds, since many of the files are quite large). It seems work fine when it receives only one file every 55 seconds or more, but when it receives two files within 55 seconds (a new file comes in while it’s already working on the last file that came in) it will only process the first file and basically seems to ignore the second one. The folder action does not become disabled anymore like it used to, but it seems to just ignore some of the files. I set a timeout of 10000 seconds, as well as a DISPLAY DIALOG on error with the error message, but I’ve yet to receive an error message after two hours.

On the other hand, the IsBusy script never worked for me, giving me an error with a variable in the IsBusy script that I saved on my hard drive and pointed the script to.

Did I interpret this line properly, or do I have to replace the (file_to_check) area with a variable??

tell application "Finder" to move alias (file_to_check) to folder "Macintosh HD:Users:Test:Desktop"

hi all,

i can reproduce this
for me, folder actions become automatically disabled following this procedure

  • mount an apple folder on a windows machine using SMB (windows filesharing)
  • attach an applescript to that folder
  • copy a file from the windows machine to that (now scripted) folder
  • abort the copy process

i.e. everytime the user aborts the copy process, the folder actions are disabled on my system

someone has more insight into how to prevent / fix this?

thanks a lot
-captswing