I already have a script that checks the contents of the folders. Its used to measure my productivity. as in how many images I have taken etc.
Now if I remember I can run when the folders are still on the desktop. However its more likely that I will move them to trash and forget to check!
So I was trying to write a folder action. (on removing items)
Then I want a script that then grabs the recently deleted items that then moves them to a temp folder so that the script can run.
The issue I have is moving the items from the trash to the temp folder to process, but must fit the conditions of the following, so that it doesn’t move unnecessary folders.
ONLY move folders that begins with MA, BU, TM etc.
and were placed in the trash in the past 5 days?
Once its in the temp folder I can run the script and then delete at later date.
Hope that makes sense and my logic too?
I’m open to suggestions how I can manage this workflow.
if I’ve understood you correctly then the below should do what you want. Attach the script as a folder action to whatever folder contains the items you’re going to delete.
When the script runs it will check to see if the deleted is a folder and if so it will check if the first 2 characters of the folder name are characters that appear in the list of prefixes. If this matches then the folder will be moved from your users .Trash folder to a temp folder of your choice.
property folderPrefixes : {"MA", "BU", "TM"}
property tmpFolder : ""
on removing folder items from this_folder after losing these_items
set trashFolder to (path to home folder as string) & ".Trash:"
if tmpFolder is "" then set tmpFolder to choose folder with prompt "Please choose a temp folder"
repeat with this_item in these_items
try
set thisFilename to do shell script "basename " & quoted form of POSIX path of this_item
set this_trashed_item to quoted form of POSIX path of (trashFolder & thisFilename)
set folder_bool to my folderCheck(this_trashed_item)
if folder_bool then
set folderPrefix to text 1 thru 2 of thisFilename
if folderPrefix is in folderPrefixes then
--display dialog thisFilename & " has been deleted"
do shell script "mv " & this_trashed_item & space & quoted form of POSIX path of tmpFolder
end if
end if
on error theError
display dialog theError
end try
end repeat
end removing folder items from
on folderCheck(this_trashed_item)
set folderStstus to do shell script "if [ -d " & this_trashed_item & " ]; then echo true;else echo false; fi;" --> check a directory exists
if folderStstus is "true" then
return true
else
return false
end if
end folderCheck