Coding's Art — #1 Web Development & Custom Web Design in Jagraon
Python Hacks • 6 min read • 10 Oct, 2026

How to Automate Annoying Daily Tasks Using Simple 20-Line Python Scripts

How to Automate Annoying Daily Tasks Using Simple 20-Line Python Scripts - Coding Tutorial Guide

Every day, we waste hours on dumb computer chores. We sort files in our download folder, rename hundreds of client invoices one by one, and copy text from websites into spreadsheets. You do not need big enterprise software to fix this. In fact, you do not even need complex code. You can solve most desk headaches with simple Python automation scripts that take less than 20 lines each.

Why Short Python Scripts Beat Heavy Software

Most automation tools are bloated, expensive, and hard to set up. When you build tiny scripts yourself, you keep total control. Python comes with batteries included. That means the standard library already has modules like pathlib, shutil, and urllib ready to do real work without installing half the internet.

We will build four battle-tested scripts today. Each one stays under 20 lines, solves a real annoyance, and runs in seconds.

Hack 1: Clean Your Messy Downloads Folder Automatically

Look at your Downloads folder right now. It is probably full of PDFs, screenshots, ZIP archives, and installation packages. This script looks at every file and moves it into a dedicated folder based on its file extension.

The 15-Line File Sorter

from pathlib import Path

DOWNLOADS = Path.home() / "Downloads"
EXT_MAP = {"pdf": "Docs", "png": "Images", "jpg": "Images", "zip": "Archives"}

for item in DOWNLOADS.iterdir():
    if item.is_file():
        ext = item.suffix.lower().lstrip(".")
        folder_name = EXT_MAP.get(ext, "Other")
        target_dir = DOWNLOADS / folder_name
        target_dir.mkdir(exist_ok=True)
        item.rename(target_dir / item.name)

Here is what happens. We point to the user directory. We scan every entry. If it is a file, we read the extension, pick the right target folder, create that folder if it does not exist, and move the file. Put this on a daily system scheduler, and your desktop will stay spotless forever.

Hack 2: Bulk Rename Messy Files with Clean Dates

Camera uploads and scanned receipts often arrive with awful names like IMG_4901_FINAL(1).jpg. Finding what you need later is painful. This script standardizes names by adding the file creation date right at the front.

The 14-Line Safe Renamer

import os
from datetime import datetime
from pathlib import Path

TARGET = Path("./scans")

for file in TARGET.glob("*.*[a-zA-Z]"):
    if file.is_file():
        mtime = os.path.getmtime(file)
        date_str = datetime.fromtimestamp(mtime).strftime("%Y-%m-%d")
        new_name = f"{date_str}_{file.name.replace(' ', '_')}"
        file.rename(TARGET / new_name)

This snippet pulls the last modification timestamp from the file system. It converts that timestamp into year, month, and day format, strips ugly spaces, and renames the file in place. You get consistent, sortable names across your whole drive.

Hack 3: Auto-Backup Critical Folders to Zip Files

Losing work hurts. Cloud drives sometimes fail to sync, and manual backups slip your mind. We can create a timestamped ZIP archive of any folder and save it to an external drive or backup directory.

The 12-Line Backup Engine

import shutil
from datetime import datetime
from pathlib import Path

SOURCE = Path("./my_notes")
BACKUP_DIR = Path("./backups")
BACKUP_DIR.mkdir(exist_ok=True)

stamp = datetime.now().strftime("%Y%m%d_%H%M%S")
archive_base = BACKUP_DIR / f"backup_{stamp}"

shutil.make_archive(str(archive_base), "zip", root_dir=SOURCE)

Python has a built-in function called shutil.make_archive. It builds complete zip files without you having to loop over single files or handle compression headers yourself. It is fast, reliable, and uses almost no memory.

Hack 4: Monitor a Web Page for Changes and Alerts

Do you keep refreshing a page waiting for concert tickets, product stock, or a price drop? Let Python do the refreshing for you. This script checks a target page every minute and prints a message when specific text appears.

The 18-Line Web Watcher

import time
import urllib.request

URL = "https://example.com/status"
KEYWORD = "In Stock"

while True:
    try:
        with urllib.request.urlopen(URL) as response:
            html = response.read().decode("utf-8")
            if KEYWORD in html:
                print(f"Alert: Found '{KEYWORD}' at {time.ctime()}!")
                break
    except Exception as err:
        print(f"Network check failed: {err}")
    time.sleep(60)

We use Python standard urllib.request so you do not even have to install third-party packages. It fetches the raw HTML, checks for your keyword, and pauses for 60 seconds between tries so you do not hammer the server.

Common Pitfalls and How to Avoid Them

Writing short scripts is easy, but small mistakes can cause headaches. Here are three errors developers hit constantly when doing desktop automation:

  • Overwriting Files with Duplicate Names: If you move a file named report.pdf into a folder that already has a report.pdf, you might erase the old one without warning. Always check target_file.exists() before calling rename.
  • Hardcoding Absolute Paths: Never write paths like C:\\Users\\John\\Documents directly in your code. Use Path.home() from the pathlib library instead. This guarantees your code runs across Windows, macOS, and Linux without syntax crashes.
  • Forgetting File Locks on Windows: Windows will lock files if another app has them open. If your Excel sheet is open in Microsoft Office, your rename script will throw a PermissionError. Wrap your file actions in a basic try...except PermissionError block to skip locked files cleanly.

Putting Your Scripts on Autopilot

A script only saves time if you do not have to open a terminal to trigger it every single hour. Once your script works, set it to run automatically on your operating system:

  • On Windows: Open Task Scheduler, create a basic task, choose your trigger, and point the action to python.exe with your script path as the argument.
  • On macOS and Linux: Open your terminal, type crontab -e, and add a single line like 0 18 * * * /usr/bin/python3 /path/to/script.py to run it daily at 6 PM.

Start small. Pick the single chore that annoyed you most today, write 15 lines of code, and automate it. Once you see your computer doing your busywork for you, you will never want to do things by hand again.

Frequently Asked Questions

Q.

Q.

Q.

HS

Hardeep Singh

Lead AI & Full-Stack Architect | Founder, Coding's Art

Hardeep is a senior software engineer and published author specializing in Python automation, enterprise Laravel systems, and autonomous AI agents. With over 8 years of hands-on experience, he designs robust digital solutions and publishes practical engineering playbooks for developers and technical leaders across India and globally.

Related Developer Guides

Chat with AI Assistant