I have had a daily maintenance script to clean out ~/Downloads via the periodic system for years. Recently I decided that I didn't want to delete the files but instead move them to ~/.Trash, allowing me to recover a file in the event I didn't move out of Downloads. The script change was easy, but since it runs as root the script finds the files but cannot move them to ~/.Trash.
The key line of the script is
find -dx . -fstype local -type f -mtime +7 -exec /usr/local/bin/trash $@ {} + -print
Documentation of the periodic.conf system is hard to find. Is there a way that I can run a script as myself instead of as root so that the script will work? I've tried su <user> -c "find -dx . -fstype local -type f -mtime +7 -exec /usr/local/bin/trash $@ {} + -print" without success.
Anyone out there know some periodic magic?
launchdand configured with a plist. The other option is to just copy the file to your trash folder which is a segue to my next question... where did/usr/local/bin/trashcome from? That's not a folder that comes default. The Trash is in~/.Trashfor each user. – Allan Jul 27 '20 at 17:15sushould work fine to drop privileges from root to you. Not sure whatexec /usr/local/bin/trash $@ {} +is about but it looks wrong. What is the$@for? – fd0 Jul 27 '20 at 18:30trash, installed via homebrew, is a CLI to move files into the user's trashcan. The-exec /usr/local/bin/trash $@ {} +is correct, per thefindmanpage and confirmation running directly at the command line. The $@ is a variable using all the files identified byfind. The entire find command does work from the command line. – Todd Vanyo Jul 27 '20 at 19:11findisn't allowed in the ~/Downloads directory, which is a classic FDA issue. – Todd Vanyo Jul 31 '20 at 02:03