DEV Community

Cover image for I Built a Python Bot That Organizes My Desktop Every Night So I Can Be Lazy πŸ˜ŽπŸ“
Nishkarsh Pandey
Nishkarsh Pandey

Posted on

18 4 6 4 3

I Built a Python Bot That Organizes My Desktop Every Night So I Can Be Lazy πŸ˜ŽπŸ“

Let’s be honest:
My desktop was a digital jungle β€” screenshots, PDFs, memes, random .zip files from 2019...

So I did what any lazy but efficient developer would do:

I built a Python script that automatically organizes my desktop every night at 11:59 PM.
It sorts files into folders like Images, Docs, Zips, etc.

Now, my desktop stays clean, and I don’t lift a finger. πŸ’…

🧠 How It Works
The script scans your desktop.
It looks at file extensions.
It moves files into categorized folders.
It can run every night using a scheduled task (Windows Task Scheduler / cron on macOS/Linux).

🐍 The Python Code:

import os
import shutil
from pathlib import Path

# Set your desktop path
desktop = Path.home() / "Desktop"

# File categories
categories = {
    "Images": [".jpg", ".jpeg", ".png", ".gif"],
    "Documents": [".pdf", ".docx", ".txt"],
    "Zips": [".zip", ".rar"],
    "Code": [".py", ".js", ".html"],
    "Videos": [".mp4", ".mov"],
    "Others": []
}

def organize():
    for file in desktop.iterdir():
        if file.is_file():
            moved = False
            for folder, extensions in categories.items():
                if file.suffix.lower() in extensions:
                    move_file(file, desktop / folder)
                    moved = True
                    break
            if not moved:
                move_file(file, desktop / "Others")

def move_file(file, destination):
    destination.mkdir(exist_ok=True)
    shutil.move(str(file), str(destination / file.name))
    print(f"Moved: {file.name} β†’ {destination}")

if __name__ == "__main__":
    organize()

Enter fullscreen mode Exit fullscreen mode

πŸ• How to Run It Automatically
πŸͺŸ Windows:
Open Task Scheduler.
Create a new task.
Set a daily trigger (e.g., 11:59 PM)

Action:
Program/script: python
Add arguments: C:\path\to\desktop_organizer.py

🍎 macOS/Linux:
Add this to your crontab:

59 23 * * * /usr/bin/python3 /path/to/desktop_organizer.py

Enter fullscreen mode Exit fullscreen mode

πŸ’Ύ GitHub Repo:
Nish2005karsh

πŸŽ‰ The Result?
Every night my desktop gets cleaned like magic β€” no guilt, no manual work.

Lazy? Maybe.
Efficient? Definitely.

πŸ’¬ What Should I Build Next?
Got a cool automation idea?
Want this to also auto-delete screenshots or organize by date?

Drop it in the comments πŸ‘‡ and I’ll try building it next!

Tiugo image

Fast, Lean, and Fully Extensible

CKEditor 5 is built for developers who value flexibility and speed. Pick the features that matter, drop the ones that don’t and enjoy a high-performance WYSIWYG that fits into your workflow

Start now

Top comments (15)

Collapse
 
nathan_tarbert profile image
Nathan Tarbert β€’

Been meaning to do this forever honestly, helps keep me from losing stuff every week.

Collapse
 
insat_vipbio_6121e73013d9 profile image
Insat Vipbio β€’

ACT prep improves time management, accuracy, and content knowledge. High ACT scores can significantly boost college admission chances.

Collapse
 
madhurima_rawat profile image
Madhurima Rawat β€’

This is a great idea! You’ve organized everything in your repository really well.

Since you’ve grouped these functions together, you could start turning them into a series. Each post can focus on one script, explaining what it does, how it works, and where it can be useful. This will help others understand your work more easily and also serve as a good way to document your progress.

Creating a series also means people can find everything in one place instead of having to search through different posts.

Collapse
 
nish2005karsh profile image
Nishkarsh Pandey β€’

Thank you so much for the kind words and valuable feedback! I really appreciate it.
Turning these into a series sounds like a fantastic idea β€” it’ll definitely make the content easier to digest and more helpful for readers who want to dive deeper into each script. Plus, documenting my progress that way will keep me motivated and organized.
I’ll start working on breaking down the scripts into focused posts soon. Looking forward to sharing more and getting feedback along the way!
Thanks again for the encouragement! 😊

Collapse
 
dotallio profile image
Dotallio β€’

Love this! I could really use an auto-archiver that moves stuff to cloud if it hasn't been opened for months - have you thought about adding that feature?

Collapse
 
nish2005karsh profile image
Nishkarsh Pandey β€’

Thank you! .That’s a brilliant ideaβ€”adding a cloud-based auto-archiving feature for inactive files would definitely level up the utility of this project. I’ve been thinking about integrating something like that using platforms like Google Drive or Dropbox via their APIs. Maybe it could scan for files untouched for, say, 90 days and then zip + upload them.

I’ll definitely consider this for the next version. Thanks again for the suggestionβ€”really appreciate it!

Collapse
 
abhinavshinoy90 profile image
Abhinav Shinoy β€’

Great idea! Helps with organizing without hassle. Thanks!

Collapse
 
nish2005karsh profile image
Nishkarsh Pandey β€’

Thanks so much, Abhinav! πŸ™Œ That was exactly the goalβ€”set it and forget it. Glad you found it helpful! Let me know if you end up tweaking it or adding features 😊

Collapse
 
melody_kelly_n profile image
Melody Kelly. N β€’

Amazing growth πŸŽ―πŸ‘

Collapse
 
nish2005karsh profile image
Nishkarsh Pandey β€’

Thanks so much, Melody! 😊 It’s been a fun journey automating little tasks like this. Excited to keep building and sharing more!

Collapse
 
grsfleettelematics profile image
GRS Fleet Telematics β€’

Amazing software

Collapse
 
nish2005karsh profile image
Nishkarsh Pandey β€’

Thanks !!😊

Collapse
 
samuraix13 profile image
SamuraiX[13~] β€’

Love your idea, would definitely use it out of respect if i used a DE, but sorry i use Windows Managers πŸ˜…

Collapse
 
nish2005karsh profile image
Nishkarsh Pandey β€’

Haha, totally fair! WM users are built different 😎πŸ’ͺ. I respect the minimalist grindβ€”maybe one day I’ll cook up a WM-friendly version too. Appreciate the love either way!

Collapse
 
bakingbad profile image
Smit β€’

This is really interesting stuff! Definitely useful when it comes to organizing things, it's a common problem. It would be interesting to learn how the program works and how it syncs with cloud storage services like OneDrive, Google Drive, or Dropbox!

Tiugo image

Fast, Lean, and Fully Extensible

CKEditor 5 is built for developers who value flexibility and speed. Pick the features that matter, drop the ones that don’t and enjoy a high-performance WYSIWYG that fits into your workflow

Start now