⚙️ Automation

Automation Script Generation

Generate Shell scripts with Cowork to automate daily repetitive tasks

★★☆ Intermediate 10-20 min January 11, 2025

Overview

Why not let your computer automatically handle repetitive daily tasks? Even if you don't know how to code, Cowork can help you generate automation scripts to eliminate repetitive work once and for all.

Use Cases

  • Scheduled file backups
  • Batch image processing
  • Automatic temporary file cleanup
  • Scheduled data synchronization
  • Auto-starting programs at boot
  • Batch file downloads/uploads

Steps

Step 1: Describe Your Automation Needs

Use natural language to describe the task you want to automate:

I want to create an automation script that:
- Automatically backs up the ~/Documents/ folder every day at 11 PM
- Backs up to external hard drive /Volumes/Backup/
- Only keeps the last 7 days of backups
- Sends a notification when backup is complete

Step 2: Claude Designs the Solution

Claude will analyze your requirements and design a solution:

I'll help you create an automatic backup script. Here's the plan:

1. Create backup script (backup.sh)
   - Use rsync for incremental backups
   - Name backup folders by date
   - Automatically delete backups older than 7 days

2. Set up scheduled task (cron/launchd)
   - Execute automatically at 23:00 daily

3. Add notification feature
   - Display system notification when backup completes

Should I create these files?

Step 3: Generate the Script

After confirmation, Claude will create the script:

#!/bin/bash
# Automatic backup script

SOURCE="$HOME/Documents/"
DEST="/Volumes/Backup/DailyBackup"
DATE=$(date +%Y-%m-%d)

# Create today's backup
rsync -av --progress "$SOURCE" "$DEST/$DATE/"

# Delete backups older than 7 days
find "$DEST" -type d -mtime +7 -exec rm -rf {} \;

# Send notification
osascript -e 'display notification "Documents backup complete" with title "Backup Script"'

echo "Backup complete: $DEST/$DATE"

Step 4: Test and Deploy

Please help me:
1. First test run this script once
2. If successful, set it to run automatically every day at 23:00

Claude will execute the test and set up the scheduled task.

Warning: Automation scripts will perform operations on your computer. Please make sure you understand the script contents, or test run in a test environment first to ensure important files won't be accidentally deleted.

Common Automation Scripts

Clean Temporary Files

Create a script that automatically cleans up every Sunday:
- Files in ~/Downloads older than 30 days
- System cache files
- Trash

Batch Image Processing

Create a script to process images in ~/Photos/Pending/:
- Compress to under 1MB
- Add watermark
- Convert to JPEG format
- Move to ~/Photos/Processed/

Development Environment Startup

Create a script to launch my development environment with one click:
- Open VS Code
- Start Docker
- Run npm run dev
- Open browser to localhost:3000

Git Auto-Commit

Create a script to automatically commit my notes updates:
- Check if ~/Notes/ has modifications
- If so, automatically git add, commit, push
- Commit message includes date and number of modified files

Tip: You can have Claude combine multiple small scripts into a "morning startup" script or "end of day" script to complete a series of operations with one click.

Advanced: Cross-Platform Scripts

Windows Batch Files

I'm using Windows, help me create a .bat script with the same functionality

Python Scripts

Implement this functionality in Python for easier future expansion

Security Recommendations

Recommendation Description
Test first Run test on a test folder
Understand before using Know what each line of the script does
Back up important data Especially when delete operations are involved
Limit permissions Don't run unnecessary scripts with admin privileges
Log history Have the script record execution history

FAQ

Q: I know nothing about programming. Can I use this?

A: Yes! Just describe what you want to automate in natural language, and Claude will generate the script and explain what each line of code does.

Q: What if the script has an error?

A: Tell Claude the error message, and it will help you diagnose and fix it.

Q: Can scripts send email notifications?

A: Yes! You can integrate system notifications, email, or even DingTalk/WeChat bots.

Real-World Example

"As a designer, I had to export design files, compress them, and upload to the server every day. Had Cowork write a script, and now it's done with one click, saving 20 minutes every day." — UI Designer