Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to make it so that the contents of the documents and desktop folder of a standard user account on a Mac gets deleted everyday at say, midnight. How can I make this happen?

share|improve this question
up vote 5 down vote accepted

~/Library/LaunchAgents/me.lri.clear.desktop.and.documents.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
    <key>Label</key>
    <string>me.lri.clear.desktop.and.documents</string>
    <key>ProgramArguments</key>
    <array>
        <string>osascript</string>
        <string>-e</string>
        <string>say "lol"</string>
        <!-- <string>tell application "Finder"
        move items of desktop to trash
        move items of (path to documents folder) to trash
        end tell</string> -->
    </array>
    <key>StartInterval</key>
    <integer>5</integer> <!-- every 5 seconds -->
    <!-- <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>23</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict> --> 
    </dict>
</plist>

The agent will be loaded after logging out and back in, or after running launchctl load ~/Library/LaunchAgents/me.lri.clear.desktop_and.documents.plist.

See man launchctl and man launchd.plist for more information.


Another option would be to add something like this to your crontab:

0 0 0 * * osascript -e 'tell app "Finder"' -e 'move items of desktop to trash' -e 'move items of (path to documents folder) to trash' -e 'end'

(You could save that as ~/.crontab, and then run crontab ~/.crontab)

share|improve this answer
    
"say lol"? Your script is evil! – Daniel Beck May 25 '11 at 10:37
    
Should be: "Muahahaha" – Andrew Lambert May 25 '11 at 18:17
    
+1 for "say lol" – Lukasa Sep 21 '11 at 12:42

It should be fairly simple with a cron job calling a shell script that deletes the contents of the specified directories

I don't have a Mac but I believe Macs come with a BASH-compatible shell. So something like this:

#!/bin/bash
rm /path/to/directory1
rm /path/to/directory2
...etc...

I'm not sure whether the Mac shell uses the classic *nix file path schema (/blah/blah) or the schema used by the Finder (blah:blah); that's something you can look into. The rm command will fail to remove subdirectories or their contents, if you want to do that use the -r switch.

share|improve this answer
    
OS X’s Unix-y bits do use the standard slash separators. – Lawrence Velázquez May 25 '11 at 3:23
    
@Lawrence Velázquez Good to know. Thanks. – Andrew Lambert May 25 '11 at 3:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .