Skip to content

Commit

Permalink
refactor: simplify screenshot script to use browser automation
Browse files Browse the repository at this point in the history
Co-Authored-By: 松村結衣(yuiseki) <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and yuiseki committed Jan 12, 2025
1 parent 3b5100a commit 33ca8d2
Showing 1 changed file with 9 additions and 56 deletions.
65 changes: 9 additions & 56 deletions scripts/gyazo-screenshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ screenshot_path="/home/ubuntu/screenshots/browser_${timestamp}.png"
# Ensure screenshots directory exists
mkdir -p /home/ubuntu/screenshots

# Install required tools if not present
if ! command -v xdotool >/dev/null 2>&1; then
echo "Installing xdotool for window management..."
sudo apt-get update && sudo apt-get install -y xdotool
fi

# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
Expand All @@ -32,58 +26,17 @@ for cmd in jq curl; do
fi
done

# Navigate to URL if provided
if [ -n "$1" ]; then
echo "Navigating to URL: $1"
# The browser navigation and screenshot commands would typically be handled by the browser automation system
# For this script, we assume the browser is already at the desired page
fi
# Find the most recent screenshot
echo "Looking for recent screenshot..."
latest_screenshot=$(ls -t /home/ubuntu/screenshots/localhost_*.png 2>/dev/null | head -n1)

# Take screenshot using browser
echo "Taking screenshot..."
# Function to take screenshot
take_screenshot() {
local url="$1"
local output_path="$2"

# If URL is provided, navigate to it
if [ -n "$url" ]; then
echo "Navigating to $url..."
# Browser navigation would happen here
sleep 2 # Wait for page load
fi

# Take screenshot using browser automation
echo "Taking screenshot..."

# Use browser automation to capture screenshot
echo "Capturing browser screenshot..."

# Check if required tools are available
if ! command -v import >/dev/null 2>&1; then
echo "Installing ImageMagick for screenshot capture..."
sudo apt-get update && sudo apt-get install -y imagemagick
fi

# Take screenshot of the active window
if command -v import >/dev/null 2>&1; then
# Get the active window ID
active_window=$(xdotool getactivewindow)
if [ -n "$active_window" ]; then
import -window "$active_window" "$output_path"
echo "Screenshot saved to: $output_path"
else
echo "Error: Could not find active browser window"
exit 1
fi
else
echo "Error: Screenshot tools not available"
exit 1
fi
}
if [ -z "$latest_screenshot" ]; then
echo "Error: No screenshot found in /home/ubuntu/screenshots/"
exit 1
fi

# Take the screenshot
take_screenshot "$1" "${screenshot_path}"
echo "Found screenshot: $latest_screenshot"
cp "$latest_screenshot" "${screenshot_path}"

# Ensure the screenshot exists and is readable
if [ ! -f "${screenshot_path}" ]; then
Expand Down

0 comments on commit 33ca8d2

Please sign in to comment.