Attach folder action to sub folder when auto generated.

I use Safari Stand to organize my downloads folder. Everyday when I download something new it creates a new dated subfolder inside my downloads folder. I thought I could manually attach a folder action script to the top (downloads folder) that would auto attach another folder action to the subfolder generated that day. Here is what I came up with so far.

on adding folder items to this_folder after receiving added_item
	tell application "System Events"
		attach action to (folder in this_folder whose creation date is (current date)) using "Macintosh HD:Users:production1:Library:Scripts:Folder Action Scripts:Attached.scpt"
	end tell
	
	
	
	
end adding folder items to

This does not seem to be working and since i’m a novice at this I am sure I am doing something wrong.

When all is said and done I would also like the original manually added script to remove the folder action from the previous day but I have not gotten that far yet.
Any thoughts?

Hi,

current date includes the time, so when you create a folder at 1:22:35 and check 2 seconds later,
it’s 1:22:37 and therefore it will never match the condition

What should I do differently?
I tried specifying the day of creation date and current date in this one but it is still not working. I am guessing this is what I need to do but I must be doing it the wrong way.

on adding folder items to this_folder after receiving added_item
	tell application "System Events"
		attach action to (folder in this_folder whose day of creation date is day of (current date)) using "Macintosh HD:Users:production1:Library:Scripts:Folder Action Scripts:Attached.scpt"
	end tell
end adding folder items to

I recommend to let AppleScript do the whole job.
This folder action attached to the download folder creates the daily folder and moves the files into it


on adding folder items to this_folder after receiving added_items
	set folderPath to POSIX path of this_folder & (do shell script "/bin/date +%y%m%d/")
	do shell script "/bin/mkdir -p " & quoted form of folderPath
	repeat with oneItem in added_items
		tell application "System Events" to set {isFolder, Nm} to {class of item (oneItem as text) is folder, name of oneItem}
		if not isFolder then
			do shell script "/bin/mv " & quoted form of POSIX path of oneItem & space & quoted form of (folderPath & Nm)
		end if
	end repeat
end adding folder items to

Note: creating a file or folder retriggers the folder action. Therefore the script prevents all folders to be affected by the move action.
But as all downloaded folders are compressed or an image, it will work.
However a separate base folder outside the hot folder is recommended.

I apologize for my inexperience with this but I do not see how this attaches any type of folder action to the newly created sub folder. I may not have made it clear but I have a folder action that needs to be attached to the subfolder that was created that day and removed from the previous day’s subfolder. I thought I could do this by having a “parent” folder action the moves the “child” folder action inside the downloads folder?

my folder action affects only the main download folder.
So instead of reassigning the folder action it manages the creation of the daily folders and the distribution of the files