Why won't script work as folder action?

I’m trying to create a folder action that will alert me when I need to back up my eMusic tunes to a DVD-R. I wrote the following script:


tell application "Finder"
     if the physical size of folder "My eMusic" is greater than 4.6E+9 then display dialog "Time to backup eMusic"
end tell

This script runs fine, but of course it does no good if I can’t trigger it to run automatically when mp3’s are added to the folder, so I put it inside a folder action routine and attached it to that folder as such:


on adding folder items to this_folder after receiving added_items
     try
          tell application "Finder"
               if the physical size of folder "My eMusic" is greater than 4.6E+9 then display dialog "Time to backup eMusic"
          end tell
     end try
end on adding folder items to

This produces nothing when an item is added. I know folder actions is properly enabled for this folder because I can get it to run Apple’s “added item alert” script. I’ve monkeyed with variations on the main script language and dialogs inside the script to see where it’s going wrong, but the best I can do is get it to produce the dialog “msng” when I’m trying to get it to display the size of the folder.

This is my first attempt to write a folder action, so I have this feeling I’m missing something elementary. But I’ve searched the forums here and can’t figure out what it might be.

Any help is appreciated.

Tried that and it didn’t work.

I was going to suggest the same, Jacques, but I couldn’t get it to work on my work Mac (10.3.9) or my home computer (10.4.3).

Model: iMac G5
Browser: Safari 416.13
Operating System: Mac OS X (10.4)

Jacques,

Thanks very much. It seems to work great.

As an added bit of weirdness, I actually got my original version to work last night briefly by playing around with the size number. I set it to zero, just to test the extreme, and it worked. Set it to 1 and it worked. Set it to 1E+9 and it worked, and so on. Then I logged off to see if it would still work when I logged back on. No go. And to add to the frustration, I tried to repeat the routine that seemed to get it going and it wouldn’t work.

Of course I’ll have trouble sleeping until I understand what the underlying issue is, but I’m at least content to have your solution. Thanks again.

-Bill Wareham

Model: iMac G4
AppleScript: 1.1
Browser: Firefox 1.0.4
Operating System: Mac OS X (10.4)