1

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?

6
  • 2
    Would using a LaunchDaemon instead work as well? – nohillside Jul 27 '20 at 16:25
  • @nohillside, do you mean using the LaunchDaemon inside the daily script? – Todd Vanyo Jul 27 '20 at 17:02
  • I concur with @nohillside - using a LaunchAgent (runs as user) would run the script with root privileges. This is done with launchd and 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/trash come from? That's not a folder that comes default. The Trash is in ~/.Trash for each user. – Allan Jul 27 '20 at 17:15
  • su should work fine to drop privileges from root to you. Not sure what exec /usr/local/bin/trash $@ {} + is about but it looks wrong. What is the $@ for? – fd0 Jul 27 '20 at 18:30
  • trash, installed via homebrew, is a CLI to move files into the user's trashcan. The -exec /usr/local/bin/trash $@ {} + is correct, per the find manpage and confirmation running directly at the command line. The $@ is a variable using all the files identified by find. The entire find command does work from the command line. – Todd Vanyo Jul 27 '20 at 19:11

You must log in to answer this question.

Browse other questions tagged .