Folder Action - removing folder items

Hi,

I’ve got a problem with this Folder Action.
What is the case:
I want to add a script to a folder that alert me if the items in the folder are going to be deleted.
I wrote this script and attached this to the Folder Action.


on removing folder items from this_folder after losing these_items 
tell application "Finder" 
set this_name to the name of this_folder 
end tell 
set the item_count to the count of these_items 
display dialog (item_count as string) & "items are deleted " & ¬ 
"from folder "" & this_name & ""." buttons {"OK"} default button 1 
end removing folder items from 

I’ve putted a few folders and files in the folder and moved this items to the Trash.
But this script doesen’t work.
Can somebody help me whith this?
Many thanks.

I don’t know why, but I can confirm that it doesn’t work even if I replace “this_folder” with an alias to the folder. You may have to list the names of the files in the script and then determine which have been removed from it in the script when the folder action fires.

I’m not at my Tiger machine at the moment, but the action certainly works in Jaguar and should do so in Tiger too, as far as I can see. Have you gone through the set-up rigmarole for Folder Actions? The script should be in a folder called “Folder Action Scripts” in your user’s “Scripts” folder, Folder Actions must be enabled, and the action must attached to the folder. It sounds like a system bug if it’s not working on Adam’s machine either.

One thing to note is that counting ‘these_items’ only tells you how many items have been removed from the folder, not where they’ve gone. You’ll need a bit more code to decide whether they’ve been deleted or moved elsewhere.

I think something in the last upgrade (to 4.10) screwed up my Folder Actions. For example, when I use the “Configure Folder Actions…” contextual menu choice for a selected folder, the Folder Actions Setup window lets me choose the folder to bear the attached script, but the second pane in which you would choose the script to attach only reveals those scripts that reside in /Library/Scripts/Folder Actions and none of those in ~/Library/Scripts/Folder Actions/. Of course the “Configure Folder Actions…” script may be busted. I have run other FAs that worked as expected. Just not this one.

Back on my Tiger machine, accessko’s script works there too.

The folder I mentioned above was called “Folder Action Scripts” (three words). On every system I’ve had where Folder Actions were available, the actions have only worked if the scripts were in this folder in the user’s “Scripts” folder. (Experimenting just now, I can attach a script that’s located elsewhere, but it only works if there’s an identical script in the “Folder Action Scripts” folder!) To avoid confusion, “Folder Action Scripts” and its contents are not displayed in Script Menu.

I also have a folder called “Folder Actions” (two words), which is displayed by Script Menu and in which I keep scripts for controlling Folder Actions.

Thanks for pointing out the contextual menu. I don’t bother with contextual menus much and hadn’t realised it was there. On my machine, the second panel of “Folder Actions Setup” shows the names of any action scripts attached to the folder whose name’s currently selected in the first panel. (If more than one folder name’s selected, no action names are shown.) Action names are shown no matter where the attached scripts happen to be, but the scripts only work if they’re in the “Folder Action Scripts” folder.

In Tiger, Folder Actions did work properly if placed in a folder ~/Library/Scripts/Folder Actions/, but that might no longer be the case. I’ll test further. I’ve changed it to ~/Library/Scripts/Folder Action Scripts/ and will pursue it further when I can.

Thanks for the replay’s guys.
So the problem exist in Leopard, and not in my script?
I’ve putted the script in the “Folder Action Scripts” but it did’t work.