Alban's Blog

How I auto-archive my desktop each week

My desktop is constantly getting cluttered with files, images, and tons of screenshots.

It's a consequence of having a thin client where I don't save many files to my computer, so the desktop has become the default place I store files when they're "in use."

So I clutter it up for a few days, get bothered by the mess, and have to sift through a dozen files with default filenames to make sure I don't need anything.

I wanted a zero-maintenence solution that:

After working with ChatGPT, I've got a simple solution that's working perfectly for me.

The approach

We're using a Zsh script to archive the files on my desktop and a LaunchAgent to run the script each Friday at 6pm.

Eventually, I'll probably add some type of auto-deletion depending on how often I go back into these archives.

How to set it up

This section is all you need to do to set this up. Replace yourname with your macOS username and paste each block into Terminal.

1. Create the script

This creates a dated archive and moves all visible files2 into the archive. I'm saving mine to a folder called "Desktop Archives."

mkdir -p ~/Scripts
cat > ~/Scripts/archive_desktop.sh <<'EOF'
#!/bin/zsh
ARCHIVE_ROOT="/Users/yourname/Desktop Archives"
DEST="$ARCHIVE_ROOT/$(date +%Y-%m-%d)"
mkdir -p "$DEST"
find "$HOME/Desktop" -maxdepth 1 -mindepth 1 ! -name '.*' -exec mv {} "$DEST" \;
EOF
chmod +x ~/Scripts/archive_desktop.sh

2. Create the LaunchAgent

This runs the shell script every Friday at 6pm without me having to think about it.

mkdir -p ~/Library/LaunchAgents
cat > ~/Library/LaunchAgents/com.cleanup.archive-desktop.plist <<'EOF'
<?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>com.cleanup.archive-desktop</string>
  <key>ProgramArguments</key>
  <array>
    <string>/bin/zsh</string>
    <string>/Users/yourname/Scripts/archive_desktop.sh</string>
  </array>
  <key>StartCalendarInterval</key>
  <dict><key>Weekday</key><integer>5</integer><key>Hour</key><integer>18</integer><key>Minute</key><integer>0</integer></dict>
</dict></plist>
EOF

Test

Once you're done you can test the script to see how it works by pasting this into Terminal.

launchctl load ~/Library/LaunchAgents/com.cleanup.archive-desktop.plist
~/Scripts/archive_desktop.sh

Conclusion

I hope this is helpful! If you have an ideas on how to improve or customize this setup please reach out on Twitter.


  1. I believe I got this idea from hearing Ben Thompson mention this exact issue and potential solution on an episode of Sharp Tech a few months ago.

  2. I think this will skip hidden files and folders, so those will stay on your desktop