Introduction
In this tutorial, you'll learn how to create a simple AI-powered assistant that can help you manage your laptop tasks using Python. This is inspired by the concept of AI transforming how we interact with our devices, as discussed in recent tech conferences. We'll build a basic command-line assistant that can perform common laptop tasks like checking system information, managing files, and running simple commands.
Prerequisites
Before starting this tutorial, you'll need:
- A computer running Windows, macOS, or Linux
- Python 3.6 or higher installed
- Basic understanding of command-line operations
- Internet connection for downloading packages
Step-by-Step Instructions
Step 1: Set Up Your Python Environment
Install Python (if not already installed)
First, verify that Python is installed on your system by opening a terminal or command prompt and typing:
python --version
If Python isn't installed, download it from python.org and follow the installation instructions for your operating system.
Step 2: Create Your Project Directory
Set up the project folder
Create a new folder on your computer called laptop_ai_assistant. This will be your project directory where we'll store all our files.
mkdir laptop_ai_assistant
cd laptop_ai_assistant
This organization helps keep your project clean and makes it easier to manage your code.
Step 3: Install Required Python Packages
Install system information and command execution libraries
We'll need several Python packages to make our assistant work. Open your terminal and run:
pip install psutil
The psutil package allows us to access system information like CPU usage, memory, and disk space. This is essential for our AI assistant to understand your laptop's current state.
Step 4: Create the Main Assistant Script
Write the basic structure of our AI assistant
Create a file called assistant.py in your project directory. Open it with a text editor and add the following code:
import psutil
import os
import subprocess
import sys
print("Welcome to your AI Laptop Assistant!")
# Function to get system information
def get_system_info():
print("\n--- System Information ---")
print(f"CPU Usage: {psutil.cpu_percent(interval=1)}%")
print(f"Memory Usage: {psutil.virtual_memory().percent}%")
print(f"Disk Usage: {psutil.disk_usage('/').percent}%")
print(f"System: {os.name}")
# Function to list files in current directory
def list_files():
print("\n--- Files in Current Directory ---")
files = os.listdir('.')
for file in files:
print(file)
# Function to execute commands
def execute_command(command):
try:
result = subprocess.run(command, shell=True, capture_output=True, text=True)
print(result.stdout)
if result.stderr:
print("Error:", result.stderr)
except Exception as e:
print(f"Error executing command: {e}")
# Main loop
while True:
print("\nAI Assistant Menu:")
print("1. Show system info")
print("2. List files")
print("3. Run command (e.g., 'ls' or 'dir')")
print("4. Exit")
choice = input("Enter your choice (1-4): ")
if choice == '1':
get_system_info()
elif choice == '2':
list_files()
elif choice == '3':
command = input("Enter command to execute: ")
execute_command(command)
elif choice == '4':
print("Goodbye!")
break
else:
print("Invalid choice. Please try again.")
Step 5: Run Your AI Assistant
Test your assistant program
Save the file and run it from your terminal:
python assistant.py
This will start your AI assistant. You'll see a menu with different options. Try selecting different choices to see how your assistant works with your laptop.
Step 6: Enhance Your Assistant with More Features
Add advanced functionality
Let's make our assistant even more useful by adding a feature to check running processes:
def list_processes():
print("\n--- Running Processes ---")
for proc in psutil.process_iter(['pid', 'name', 'cpu_percent']):
try:
print(f"PID: {proc.info['pid']}, Name: {proc.info['name']}, CPU: {proc.info['cpu_percent']}%")
except (psutil.NoSuchProcess, psutil.AccessDenied):
pass
Add this function to your assistant.py file, then update your menu to include option 5 for listing processes:
print("5. List running processes")
# In the main loop:
elif choice == '5':
list_processes()
This enhancement allows your assistant to show what programs are currently running on your laptop, giving you better control over your system resources.
Step 7: Test All Features
Verify everything works correctly
Run your assistant again and test all features:
- Check system information
- List files in your directory
- Run a simple command like 'ls' (Linux/macOS) or 'dir' (Windows)
- View running processes
This demonstrates how AI can help you understand and control your laptop more effectively.
Step 8: Make It More User-Friendly
Improve the interface
Let's add some helpful prompts and better formatting to make our assistant more intuitive:
print("\n" + "="*50)
print(" AI LAPTOP ASSISTANT")
print("="*50)
Place this at the beginning of your main loop to create a cleaner, more professional-looking interface.
Summary
In this tutorial, you've created a basic AI-powered laptop assistant using Python. This assistant can check system information, list files, execute commands, and show running processes. While this is a simple implementation, it demonstrates the core concept of how AI can make our laptops smarter and more responsive to our needs.
The assistant uses Python libraries like psutil to access system information and subprocess to execute commands. This approach shows how we can build intelligent tools that help us manage our devices more effectively.
As technology advances, we can expect these kinds of AI assistants to become even more sophisticated, offering natural language processing, predictive capabilities, and deeper integration with our computing environments.



