Automatically Delete Files From Downloads Folder Daily Unless Tagged With "Keep"? How can I automate the deletion of files from my downloads folder but keep files I've tagged with &quot;Keep&quot;? I've been able to use Automator to delete files daily, but I can't work with tags in Automater. Most likely this requires AppleScript (I'm fairly new to AppleScript). I've created an AppleScript to delete files from Downloads folder, but it's not working (I can't tell if it's a permissions issue), and I'm lost on how file tags/labels work in AppleScript.
try
    tell application &quot;Finder&quot;
        delete (every item of folder &quot;/Users/wheel58m/Library/Mobile Documents/com~apple~CloudDocs/Downloads&quot;)
    end tell
    
on error
    display dialog (&quot;Error. Couldn't Move the File&quot;) buttons {&quot;OK&quot;}
end try

Any documentation or resources is appreciated.
Automatically Delete Files From Downloads Folder Daily Unless Tagged With “Keep”?

The following example AppleScript code can be used in a shell script with an /usr/bin/osascript shebang, or an AppleScript script/application, or a Run AppleScript action in an Automator workflow to delete any file in the targetFolder that does not have a custom &quot;Keep&quot; Tag set in Finder:
-- # targetFolder can be either an HFS path or a POSIX path,
-- # &quot;path:to:target:folder:&quot; or &quot;/path/to/target/folder&quot;
-- # 
-- # Change the value of targetFolder from &quot;/path/to/target/folder&quot;
-- # to the appropriate fully qualified pathname in either form.

set targetFolder to &quot;/path/to/target/folder&quot;


-- # The remaining code should not need to be modified, 
-- # unless the mdfind query needs to be changed.

set targetFolderPOSIXpath to ¬
    the quoted form of ¬
        the POSIX path of targetFolder

set shellCMD to {¬
    &quot;mdfind -onlyin&quot;, space, targetFolderPOSIXpath, space, ¬
    &quot;'! kMDItemKind == Folder &amp;&amp; ! kMDItemUserTags == Keep'&quot;} ¬
    as string

set posixFilesToDelete to ¬
    paragraphs of ¬
    (do shell script shellCMD)

set filesToDelete to {}
repeat with thisFile in posixFilesToDelete
    set thisFile to POSIX file thisFile as alias
    set the end of filesToDelete to thisFile
end repeat

if filesToDelete is not {} then ¬
    tell application &quot;Finder&quot; to ¬
        delete filesToDelete 

Note: Scroll as necessary to see remaining code.


Notes:

As I do not have the target folder mentioned in the OP, I could not test for any permissions issues that may need addressing in: System Preferences &gt; Security &amp; Privacy &gt; Privacy
The example AppleScript code was tested and work for me without issue in macOS Catalina using a temporary folder created within my Home folder while adding files and folders to it and tagging only some files with a custom &quot;Keep&quot; Tag in Finder.
As to &quot;Automatically Delete Files&quot; there are a number of different ways to accomplish this depending on how the example AppleScript code is used. Used as an AppleScript shell script or application it can be scheduled to run at whatever time you'd like, using any of several different methods.

As an AppleScript application using: Calendar
As an AppleScript shell script using: launchd or cron




Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.