Skip to content

Instantly share code, notes, and snippets.

@simonw
Created October 29, 2024 15:05
Show Gist options
  • Select an option

  • Save simonw/a26046b0f9d74c46ee5af6eb47b73db9 to your computer and use it in GitHub Desktop.

Select an option

Save simonw/a26046b0f9d74c46ee5af6eb47b73db9 to your computer and use it in GitHub Desktop.

2024-10-29T15:04:52 conversation: 01jbccxm90853ja0kjwbhbq8g7

Model: claude-3-5-sonnet-latest

Prompt:

Write me a concise Bash script that loops through every .jpg or .jpeg in a directory and runs this against each one: llm -m gpt-4o-mini 'return just the alt text for this image' image1.jpg > image1.txt

Response:

Here's a concise Bash script that does what you've described:

#!/bin/bash

for img in *.{jpg,jpeg}; do
    if [ -f "$img" ]; then
        output="${img%.*}.txt"
        llm -m gpt-4o-mini 'return just the alt text for this image' "$img" > "$output"
    fi
done

This script:

  1. Loops through all .jpg and .jpeg files in the current directory
  2. Creates an output filename by replacing the image extension with .txt
  3. Runs your llm command on each image and saves the output to the corresponding text file
  4. The -f check ensures the file exists (prevents errors if no matches are found)

Save this as a .sh file, make it executable with chmod +x script.sh, and run it in the directory containing your images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment