Folder Action Dispatcher Running at 99% Processes

I have 2 folder actions running on my system. The First is to move stack overlay icon from folder A to folder B and back to folder A so that it stays visible in the stack when i sort by “Data Added”. The Second it to auto open .torrent files when added to the downloads folder. Every hour or so my Folder Action Dispatcher.app start run really high Processes(99%). The only way to get the processes down is to force quit it. I’m sure it has something to do with the folder actions buy don’t know how to fix it…please help

Script 1

on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		set file_list to name of every file of this_folder
		repeat with this_item in file_list
			if this_item begins with "-" and this_item ends with ".icns" then
				set icon_name to this_item
				exit repeat
			end if
		end repeat
		do shell script "mv -f " & quoted form of (POSIX path of this_folder & icon_name) & " /tmp"
		do shell script "mv -f " & quoted form of ("/tmp/" & icon_name) & " " & quoted form of (POSIX path of this_folder)
	end tell
end adding folder items to 

Script 2

on adding folder items to this_folder after receiving added_items
	tell application "Finder" to repeat with this_item in added_items
		if name extension of this_item is "torrent" then
			open this_item
			delay 15
			delete this_item
		end if
	end repeat
end adding folder items to

Hi, gotmoney.

You’ve got an eternal loop in the first script. Every time it moves the .icns file back into the watched folder, it retriggers the folder action and sets itself off again!

Thanks…is there a way to fix the script so there is no loop.

would this one work better…just wondering…im a newbie

on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		set icnsFiles to files of this_folder whose name extension is "icns" and name starts with "-"
	end tell
	
	if icnsFiles is not {} then
		tell application "Finder" to set icon_name to name of (item 1 of icnsFiles)
		do shell script "mv -f " & quoted form of POSIX path of ((this_folder as text) & icon_name) & " /tmp"
		do shell script "mv -f " & quoted form of POSIX path of ("/tmp/" & icon_name) & " " & quoted form of POSIX path of this_folder
	end if
end adding folder items to

I think I may have been wrong about the reintroduction of the file retriggering the folder action. It’s a common mistake to have a folder action rename items in the folder, which fools the watching system into thinking the folder’s contents have changed again and retriggering the action. I assumed that removing the file and putting it back was doing the same thing. But while trying out an idea for a work-round, I haven’t been able get the system to notice the actual change of contents taking place!

Apologies for the noise. :rolleyes:

really…in other ideas to get Folder Actions Dispatcher to stop running at 99% processes…

The first thing to do is determine which folder action is causing the problem. I would remove one folder action and run it that way for awhile and see if the problem occurs. Then I would do the same with the other. If it only occurs on one and not the other then you have focussed the problem. If it occurs on both (or neither) then you know it’s a problem with folder actions in general.

Another idea… I really don’t like the idea of moving the file back and forth to accomplish your task. An easier method would be to 1) make the dock icon display itself as a folder rather than a stack and 2) set the icon for the folder. Then you have a static icon which won’t change no matter how you sort the folder. If you need a programmatic method to set the folder icon, as opposed to setting the folder icon manually yourself, then you can use a tool I wrote for doing that. You can find that tool here. And if you often change the icon using that tool and notice that the dock icon doesn’t get updated then you can try quitting the dock after setting it’s icon. The dock will auto-launch after quitting and it might auto-update it’s icon too.

But really the first thing to do is find out which folder action is causing the problem.

Hey Guys…After a day to test both scripts, i figured out that it is the folder action that moves the “.icns” file. The reason i don’t set the folder icon to stack icon is because the contents inside the folder wont be visible in the stack. it will just be the stack and that is it…

If you use do shell script “touch ” and order you stack by creation date would solve your problem. Maybe you have to use a do shell script "killall Dock" to update the dock.

If you mind the order of creation date simple touch every file that will be added. Then the files will automatically have it’s creation identical to added date so it doesn’t matter if it’s sorted by creation date

That sounds like a good idea, but im not sure how to write the script for that. Im a Newbie

something like this maybe?


on adding folder items to this_folder after receiving added_items
	repeat with thisItem in addedItems
		do shell script "touch " & quoted form of posix path of added_items
	end repeat
	try
		set theFile to do shell script "ls " & quoted form of POSIX path of (this_folder) & "| grep -i '^-.*\\.icns$' | awk '{print \"" & (POSIX path of (this_folder)) & "\" $0 }' | head -1"
	on error
		return
	end try
	do shell script "touch " & quoted form of theFile
end adding folder items to

I forgot to tell how to update the dock.

tell application "Dock" to quit -- it will restart automatically

Thanks…But that didn’t work. Any other ideas :smiley:

this will abort immediately with a ‘The variable addedItems is not defined’ error

change it to


on adding folder items to this_folder after receiving added_items
	repeat with thisItem in added_items
		do shell script "touch " & quoted form of POSIX path of thisItem
	end repeat
	.

Weird… it worked perfectly on my machine. because it worked well and like expected i’ll step out.

Thanks for the heads up Stefan.

I was just think about something. What if i add a force Quit Script to the end on my original Script. That way if the CPU Processes get to high, Folder Action Dispatcher will be quit and reopen automatically…

on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		set file_list to name of every file of this_folder
		repeat with this_item in file_list
			if this_item begins with "-" and this_item ends with ".icns" then
				set icon_name to this_item
				exit repeat
			end if
		end repeat
		do shell script "mv -f " & quoted form of (POSIX path of this_folder & icon_name) & " /tmp"
		do shell script "mv -f " & quoted form of ("/tmp/" & icon_name) & " " & quoted form of (POSIX path of this_folder)
	end tell
end adding folder items to 

Like Nigel said, your script has an infinite loop. Don’t try to ignore that, solve that problem first.

I thought he said he may have been wrong. How do i solve that problem. The touch command works, but i have to kill the dock to get it to display properly.

Is killing the dock a problem for you? if it’s a visible dock I agree with you that it doesn’t look pretty.

another approach so it looks and feels the same is downloading the files to an invisible folder for example a .download. then you set the folder action to that invisible folder. When a file is added to that invisible folder it you’ll move the files from the the invisible download folder to the visible download folder. Keep a copy of your icon in the invisible folder and at last copy (not move) the icon to the visible folder so it will be added at last and will be visible. The dock will be automatically updated so you don’t need a quit of the dock.

that sounds like it will work.:D…But how would i script that. Its a little out of my league.