Move file into a folder created by AS - Cannot get a proper reference

Hello. Here is my goal:

  1. Use an AS to generate some folder structure for client projects (main folder, subfolders inside this, etc.) I have this part working, and it does exactly what I want.

  2. Need to add to above script - Assigning and enabling a Folder Action script that does this:
    As files are copied into the “MP4” folder, need to create a new folder inside this, with a foldername like “Can be deleted after 11/25/2018”. Using the date object, and adding 90 days to current date, I have this part of the script working fine. Folder gets created and named as I want it to.

  3. Here is the problem part - Moving the mp4 file copied into the MP4 folder (main folder with Folder Action assigned). I cannot get the pasted-in file to move into the programmatically created folder. This may have something to do with “as alias” or “POSIX Path”, which I have not yet understood how to use these properly. To further confuse things, when the programmatically created folder is made, it is now an item added to the main folder, thereby triggering the “on adding folder items to” folder handler.

So I cannot figure out how to grab a reference to the mp4 files added to main folder, and manipulate them in a way that I can move into the programmatically created folder. I have tested simple syntax of just moving a file into a folder. Got that - it works. But my example is trickier. Also, does my newly created folder get added to “added_items” list? Or does it append to the list?
Here is my code so far:


(*
	Add Dates to Delete to items copied into this folder
*)


global added_items
global destinationFolder
global this_folder

on adding folder items to this_folder after receiving added_items
	
	tell application "Finder"
		
		-- Testing this way before setting up a loop for multiple files pasted in. Sets first pasted-in file as "newFile"
		-- Do I need "as alias" here?
		-- And does this kind of reference work?		
		set newFile to first item of added_items as alias
		
		
		-- Add 90 days to the current date. Put it in a variable called theDeleteDate
		set theDeleteDate to the ((current date) + days * 90)
		
		-- Create new Destination Folder with added Delete Date in filename
		set destinationFolder to make new folder at this_folder with properties {name:" - This Folder Can Be Deleted After " & short date string of (theDeleteDate)}
		
		-- Move pasted item into newly created folder
		-- This is not working. File does not move into destinationFolder
		move file newFile to folder destinationFolder
		
		
	end tell
	
end adding folder items to

Hi. As you’ve discovered, making a folder in the watched folder triggers the script by adding an item for processing, which is an expected function/drawback for Folder Actions. Further, POSIX paths are unknown to Finder, and dropped items are already held in an alias list.

on adding folder items to theFolder after receiving addedAliases
	set theDeleteDate to ((current date) + days * 90) --standard additions like 'current date' live outside tell blocks or should be escaped with ‘my’
	tell application "Finder"
		try
			set folderTarget to (make folder at desktop with properties {name:"This Folder Can Be Deleted After " & theDeleteDate's short date string}) --result is alias
		on error --may already exist from prior run
			set folderTarget to folder ("This Folder Can Be Deleted After " & theDeleteDate's short date string) --assumes lives on desktop; hard-code as needed
		end try
		repeat with this in addedAliases
			move this to folderTarget
		end repeat
	end tell
end adding folder items to

edit: added try block to avoid problems from previous runs

Thank you very much, Marc!

Made a couple tweaks for my folder path, and this does exactly what I needed. Really appreciate the help.

Shane
Also in Dallas, TX, btw.