Hello. Here is my goal:
-
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.
-
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. -
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