Folder Action (image processing) problem

I am having a problem with a Folder Action script that I have written.

The script is part of a set to help with processing digital images. To help organize images I have created a “sorting folder”. When new images are added to the folder it automaticly creates a new subfolder and moves all the added files into that.

The obvious problem is that the creation of the new subfolder triggers the Folder Action to run again… creating another new subfolder and moving the previous subfolder into that…which triggers the Folder Action again…

Does anyone have an elegant way to keep the folders that my sorting action creates from triggering recursive sorting actions.:?: :?:

The only thing I can think of is to detach the FA script from folder at the start of the action and reattach it when the action concludes. This could get messy for folders with multiple actions attached.

Thanks for any suggestions,

Or make some tests within your FA. For example:

if it was dropped only 1 item then
     if such item is a folder then
          return --> no actions, no results

You could name the new folder that you create to house the sorted files with some unique prefix or suffix like “sorted_images_” and then in your FA script, check the name of the added items. If it starts with the unique prefix (or if you’ve chosen to go with a unique suffix instead, if it ends with that suffix), stop the process by returning false, otherwise continue.


I think I found my own solution… :shock: :!: :!: :smiley:

First thanks to the authors of the previous replies. I had considered both alternatives but the folder action must be able to accomodate any number of added items so that rules out that alternative and I have written the handler that does all the sorting to take parameters of custom prefix and suffix (looking down the road I think these will be important) so there goes the other althernative

As I looked this morning more closely at the contents of the (Panther) “Macintosh HD:Library:Scripts:Folder Actions:” folder and examined the scripts Attach Sript to Folder.scpt and Disable Folder Actions.scpt I noticed that the application that they are talking to is “System Event”. When I checked the dictiony for this appications I found that the Folder Actions Suite defines a script class that has a property enabled which is boolean.

I will try rewriting the script later today and using this property to switch the script on and off just long enough to make the new folders and post the result.

Um, what? I don’t follow. This is what I meant:

on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		set this_folder to this_folder as string
		set time_stamp to do shell script "date +%Y%m%d%H%M"
		repeat with this_item in these_items
			if name of this_item ends with "_sorted_items" then return
				get (this_folder & time_stamp & "_sorted_items") as alias
			on error
				make new folder at folder this_folder with properties {name:(time_stamp & "_sorted_items")}
			end try
			move this_item to folder (this_folder & time_stamp & "_sorted_items")
		end repeat
	end tell
end adding folder items to

No need to toggle FA off and on.



You might be able to move all of the items simultaneously if you select them. Then there’s no need to loop through the items.

set newFolder to this_folder & time_stamp & "_sorted_items"
		move the selection to folder newFolder of this_folder
	end try

You’re right that you could move them all at once–unless one of them was the new folder that the action just created to store them. That’s why I iterate through each item.


I was thinking along the lines that new folders that get created don’t get automatically selected. Of course… there are dozens o’ solutions whenever we talk of AS. I haven’t tried it, but I think you’d get an error if you tried to move the folder into itself. This should be fine as long as it’s wrapped in the TRY loop… meaning it will cause an error, but ignore the error since it was only told to try to do the action if it could.