10 Python automation scripts for everyday computer operations with code examples

Itexamtools.com
2 min readMay 10

--

These specially designed 10 automation scripts in python will make your life easy in daily computer operations and work.and it’s in your most loved language: PYTHON!

  1. Automatic Backup Script: This script automatically backs up selected files to a specified location.
import shutil

source = '/path/to/source/folder'
destination = '/path/to/backup/folder'

shutil.copytree(source, destination)

2. File Renaming Script: This script automatically renames all files in a folder to include a timestamp.

import os
import time

folder_path = '/path/to/folder'

for filename in os.listdir(folder_path):
timestamp = time.strftime('%Y%m%d-%H%M%S')
new_filename = f'{timestamp}-{filename}'
os.rename(os.path.join(folder_path, filename), os.path.join(folder_path, new_filename))

3. Desktop Cleanup Script: This script automatically moves all files on the desktop to a specified folder.

import os
import shutil

desktop_path = os.path.expanduser('~/Desktop')
destination_folder = '/path/to/destination/folder'

for filename in os.listdir(desktop_path):
source_path = os.path.join(desktop_path, filename)
destination_path = os.path.join(destination_folder, filename)
shutil.move(source_path, destination_path)

4. Email Automation Script: This script automatically sends an email with a specified message and subject to a specified email address.

import smtplib
from email.mime.text import MIMEText

SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = 587

sender_email = 'sender_email_address@gmail.com'
sender_password = 'sender_email_password'

recipient_email = 'recipient_email_address@gmail.com'
subject = 'Email Subject'
message = 'Email Body'

msg = MIMEText(message)

msg['Subject'] = subject
msg['From'] = sender_email
msg['To'] = recipient_email

with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as smtp:
smtp.starttls()
smtp.login(sender_email, sender_password)
smtp.send_message(msg)

5. File Download Script: This script automatically downloads a specified file from the internet.

import requests

file_url = 'http://example.com/file.txt'
destination_path = '/path/to/destination/folder/file.txt'

response = requests.get(file_url)

with open(destination_path, 'wb') as f:
f.write(response.content)

6. Password Generator Script: This script automatically generates a random password of a specified length.

import random
import string

length = 10

password = ''.join(random.choices(string.ascii_letters + string.digits, k=length))

print(password)

7. Screensaver Activation Script: This script automatically activates the screensaver.

import ctypes

ctypes.windll.user32.SendMessageW(0xffff, 0x0112, 0xF140, 0)

8. System Shutdown Script: This script automatically shuts down the computer after a specified number of seconds.

import os
import time

shutdown_time = 60 # in seconds

time.sleep(shutdown_time)

os.system('shutdown /s /t 1')

9. Volume Control Script: This script automatically adjusts the volume of the computer.

import pyautogui

pyautogui.press('volumeup') # increase volume
pyautogui.press('volumedown') # decrease volume

10. Web Scraping Script: This script automatically scrapes data from a specified website.

import requests
from bs4 import BeautifulSoup

url = 'http://example.com/'

response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')

# find all links on the page
links

happy coding with this scripts! more useful stuff you will find always if you subscribe to my medium.

for more IT Knowledge, visit https://itexamtools.com/

check my IT blog — https://itexamsusa.blogspot.com/

check my Medium IT articles https://itcertifications.medium.com/

Join my facebook IT group — https://www.facebook.com/groups/itexamtools

--

--

Itexamtools.com

At ITExamtools.com we help IT students and Professionals by providing important info. about latest IT Trends & for selecting various Academic Training courses.