Why does System Events hate me so?

Mikuro

Crotchety UI Nitpicker
Not sure if this should be here or in the Programming & Scripting forum. But I really don't think it's a problem with my script, so I'm putting it here.

The problem is with Folder Actions (which, for those who don't know, is controlled by an invisible process called System Events). Quite often, when a script is triggered, System Events just starts hanging. Which, in turn, makes the Finder start hanging. The only way to escape this is to open up Activity Monitor and force-quit System Events. Then if I want my folder action to actually do its thing, I need to re-enable Folder Actions in the Finder.

Any idea how I could fix this? The problem is happening more and more with 10.4.2. It used to be that it'd happen once a week or so, but now it happens so often that the entire feature is simply unusable.

It also seems to happen more since I backed up and restored my OS. But I just copied my system to and from another disk; it's the exact same system as it was before, so I don't see why that should be an issue.



I don't think it's a problem with my script (it worked fine for a year or so under Panther), but for the sake of thoroughness, here's all you could ever want to know about the particular script in question:

I use Folder Actions to automatically sort my web downloads folder. Every time I download a file in Safari (or any browser), my script does two things: adjusts its modification date of any downloaded file (exclusing those that are actively being downloaded) to the current date+time, and moves it into a folder based on its name extension. Here's the script itself:
Code:
on opening folder this_folder
	doStuff(this_folder)
end opening folder

on doStuff(this_folder)
	tell application "Finder"
		set modification date of (every file of this_folder) to the current date
		if the number of items of (every item of this_folder whose name ends with ".torrent") > 0 then
			move (every item of this_folder whose name ends with ".torrent") to folder "Torrents" of this_folder
		end if
		if the number of items of (every item of this_folder whose name ends with ".sgf") > 0 then
			move (every item of this_folder whose name ends with ".sgf") to folder "Go games" of this_folder
		end if
		move (every file of this_folder whose name does not end with ".download" and name does not end with ".part") to folder "Other" of this_folder
	end tell
end doStuff
As you can see (if you're fluent in AppleScript and care to read the whole script), it siphons off torrents into one folder, sgfs into a second, and everything else into a third. The reason I mess with the modification date is so that I can sort my downloads by date modified and have them listed in the order I downloaded them (sometimes when you download a file from the web, it will have have a pre-assigned modification date, which is why I need to go out of my way to do this).

Note that normally I have the script do its thing (in the every-so-decriptively titled "doStuff" handler) both when it's being opened AND whenever a file is added to the folder. I simplified it to this form (which only processes the files when it's opened), thinking maybe that would help with my problem, but it's still just as unstable.
 
Back
Top