How to Automate Boring Tasks with Python (Using pyautogui, os, shutil)
In today’s fast-paced digital world, spending hours on repetitive tasks like renaming files, organizing folders, clicking buttons, or even…
How to Automate Boring Tasks with Python (Using pyautogui, os, shutil)
In today’s fast-paced digital world, spending hours on repetitive tasks like renaming files, organizing folders, clicking buttons, or even typing reports is not just boring — it’s inefficient. Thankfully, Python, with its vast ecosystem of libraries, allows us to automate mundane tasks and free up time for more meaningful work.
In this blog, we’ll explore how you can automate your daily computer activities using Python, with a focus on three powerful libraries:
[pyautogui](https://pypi.org/project/pyautogui/) – for GUI automation (mouse, keyboard)[os](https://docs.python.org/3/library/os.html) – for file and directory handling[shutil](https://docs.python.org/3/library/shutil.html) – for file copying, moving, and cleanup
Why Automate?
Before we dive in, let’s quickly answer: why should you automate tasks with Python?
- Save time on repetitive workflows
- Eliminate human error
- Run tasks unattended or on schedule
- Improve consistency and productivity
Whether you’re a student, developer, researcher, or office worker, automation can boost your efficiency.
Getting Started
Let’s install the necessary packages:
pip install pyautogui
os and shutil are built-in, so no installation needed.
Automating File Management with os and shutil
Task: Organize files into folders based on file type
Let’s say your Downloads folder is a mess. You want to organize files into folders like Images, Documents, and Videos.
Logic
- Loop through all files in a directory
- Check their extensions
- Move them to the correct folder using
shutil.move()
Code:
import os
import shutil
# Path to your downloads folder
downloads_path = '/Users/yourname/Downloads'
# Define destination folders
file_types = {
'Images': ['.jpg', '.jpeg', '.png', '.gif'],
'Documents': ['.pdf', '.docx', '.txt', '.xlsx'],
'Videos': ['.mp4', '.mov', '.avi'],
'Archives': ['.zip', '.rar', '.7z']
}
# Make folders if they don't exist
for folder in file_types:
os.makedirs(os.path.join(downloads_path, folder), exist_ok=True)
# Loop through files
for filename in os.listdir(downloads_path):
filepath = os.path.join(downloads_path, filename)
if os.path.isfile(filepath):
_, ext = os.path.splitext(filename)
for folder, extensions in file_types.items():
if ext.lower() in extensions:
dest = os.path.join(downloads_path, folder, filename)
shutil.move(filepath, dest)
print(f"Moved: {filename} ➜ {folder}")
Output
Your files will now be nicely sorted into folders.
Bulk Renaming Files with os
Task: Rename files in a folder to a specific pattern
Let’s say you have hundreds of scanned documents like IMG_001.jpg, IMG_002.jpg, and you want them renamed to Invoice_1.jpg, Invoice_2.jpg, etc.
Code:
folder_path = 'C:/Users/YourName/Documents/Scans'
for i, filename in enumerate(os.listdir(folder_path)):
if filename.endswith('.jpg'):
new_name = f"Invoice_{i + 1}.jpg"
old_path = os.path.join(folder_path, filename)
new_path = os.path.join(folder_path, new_name)
os.rename(old_path, new_path)
print(f"Renamed {filename} to {new_name}")
Automate Keyboard and Mouse with pyautogui
The pyautogui library simulates human keyboard and mouse input. You can use it to:
- Fill forms
- Open apps
- Click buttons
- Take screenshots
- Automate GUI workflows
⚠️ Be careful: It controls your actual mouse & keyboard.
Task: Automatically type a message into Notepad
import pyautogui
import time
import os
# Open Notepad (Windows)
os.system('notepad.exe')
time.sleep(2)
# Type the message
pyautogui.write("Automating boring stuff with Python is amazing!", interval=0.1)
pyautogui.press('enter')
pyautogui.write("Let Python do the typing 😎", interval=0.1)
Output
It opens Notepad and types the message automatically.
Task: Take Screenshots Every 10 Seconds
Useful for time-lapse or monitoring.
import pyautogui
import time
for i in range(5):
screenshot = pyautogui.screenshot()
screenshot.save(f'screenshot_{i}.png')
print(f"Captured screenshot_{i}.png")
time.sleep(10)
Task: Move the Mouse in a Pattern
You can make your computer look alive 🤖
import pyautogui
import time
for i in range(3):
pyautogui.moveTo(100, 100, duration=0.5)
pyautogui.moveTo(400, 100, duration=0.5)
pyautogui.moveTo(400, 400, duration=0.5)
pyautogui.moveTo(100, 400, duration=0.5)
Scheduling Automation with Task Scheduler / Cron
Once your script is ready, you can schedule it:
On Windows:
Use Task Scheduler
- Create Basic Task
- Choose trigger (e.g., daily)
- Choose “Start a Program” ➜
python.exewith your script path
On Linux/macOS:
Use cron jobs:
crontab -e
Example to run every day at 8am:
0 8 * * * /usr/bin/python3 /path/to/your_script.py
Tips for Safe Automation
- Always test scripts in a dummy folder
- Use
time.sleep()to slow down GUI scripts - Avoid running mouse/keyboard scripts when unsupervised
- Use
try-exceptto handle errors gracefully
Real-World Use Cases
Here’s how people use Python automation in real jobs:
Role Use Case Data Analyst Automatically download reports, clean CSVs, generate visualizations HR Manager Bulk rename resumes, send emails, fill forms Developer Auto-test apps, deploy code, rename logs Student Organize class notes, backup files, auto-type study material Freelancer Generate invoices, move client files, schedule reminders
Further Libraries to Explore
[schedule](https://pypi.org/project/schedule/): For in-code task scheduling[watchdog](https://pypi.org/project/watchdog/): Trigger scripts on file system changes[pynput](https://pypi.org/project/pynput/): More keyboard/mouse control[openpyxl](https://pypi.org/project/openpyxl/): Excel automation
Bonus: Automate Excel Reports
import openpyxl
wb = openpyxl.load_workbook('report.xlsx')
sheet = wb.active
sheet['A1'] = 'Generated by Python'
wb.save('report_updated.xlsx')
Conclusion
Python is more than just a programming language — it’s a personal assistant. By learning to automate boring tasks using pyautogui, os, and shutil, you unlock a superpower that:
- Saves you hours weekly
- Minimizes human error
- Boosts your productivity
Whether you’re renaming 500 files, clicking 50 buttons, or organizing messy folders — let Python handle it.
What Next?
- Try automating your desktop routine.
- Create an automation script for your office work.
- Share your automation story online!
메타데이터
- post_id
- d195a126bcdb
- slug
- how-to-automate-boring-tasks-with-python-using-pyautogui-os-shutil-d195a126bcdb
- url
- https://medium.com/@tusharkantatk/how-to-automate-boring-tasks-with-python-using-pyautogui-os-shutil-d195a126bcdb
- canonical_url
- https://medium.com/@tusharkantatk/how-to-automate-boring-tasks-with-python-using-pyautogui-os-shutil-d195a126bcdb
- author_url
- https://medium.com/@tusharkantatk
- status
- ok
- fetched_at
- 2026-07-18 16:58:14