GUI dev: Add a face to it. scrotyad example

This past week I had some time, so I sat down and evaluated the scrot script I use. Time intervals, number of screen captures, output path. Sometimes, there are tools we use infrequently and therefore, need a script or remember the syntax with parameters. Some users cannot use a man page. Some tools do not have a man page but help, info, or minihowto.

Regardless, a front end tool to use some simple commands can be done with yad or dialog. You can use tkinter and python or create an electron app with javascript and xml. Alternately, if it’s worth your time, create a SaaS for the product with tiers.

I believe the reason there hasn’t been a “year of the desktop” is twofold. 1. GNU Linux is more of a dev operating system. The simplicity of throwing up a server, quick commands, easy administration. and 2. The people who want year of the desktop are not devs.

Having started an installfest in AZ in 2003, and attended twice monthly with alternate weeks holding Linux User group meetings, I absolutely believe users want nothing to do with the command line.

If you really want “year of the desktop” I suggest the following:

  • Listen to users
  • Make tools simple
  • Create simple solutions, not just features
  • Listen to the users. Create tools so users never need the cl

Some key areas:

  • Logs
  • GUI tools – wget, curl, scrot maybe even coreutils
  • Better File Manager
  • Better Desktop environment
  • non irritating voice control – not choppy
  • ai tools – webui for textgen, stable ui, ui for different demos using onnx, pytorch, kaldi, gan, yolo ultralytics etc.
  • easy documentation tools: scrot and pandoc
  • a good editor

Here is an example of scrot with yad.

#!/bin/bash
# Jan 2025 - marcia wilbur GPL v3.0 +

# Ensure required tools are installed
if ! command -v scrot &> /dev/null || ! command -v yad &> /dev/null; then
  echo "Please install 'scrot' and 'yad' to use this app."
  echo "On Debian-based distros, run: sudo apt install scrot yad"
  exit 1
fi

# Default settings
OUTPUT_DIR="$HOME/Pictures"
INTERVAL=5
LENGTH=1
DATE_FORMAT="%Y-%m-%d_%H-%M-%S"
NOTIFY_ENABLED=true

# Function to display the yad interface
run_yad_interface() {
  yad --form \
    --title="Scrot Screenshot Tool" \
    --width=400 \
    --field="Save Path:DIR" "$OUTPUT_DIR" \
    --field="Interval (seconds):NUM" "$INTERVAL" \
    --field="Number of Screenshots:NUM" "$LENGTH" \
    --field="Date Format:ENTRY" "$DATE_FORMAT" \
    --field="Enable Notifications:CHK" "$NOTIFY_ENABLED" \
    --button="Start:0" \
    --button="Cancel:1"
}

# Function to take screenshots
take_screenshots() {
  local path="$1"
  local interval="$2"
  local length="$3"
  local date_format="$4"
  local notify="$5"

  echo "Starting screenshot sequence..."
  for ((i = 0; i < length; i++)); do
    # Generate filename with timestamp
    local timestamp
    timestamp=$(date +"$date_format")
    local filename="$path/screenshot_$timestamp.png"

    # Take the screenshot
    scrot "$filename"

    # Notify user if enabled
    if [[ "$notify" == "TRUE" ]]; then
      notify-send "Screenshot Taken" "Saved as: $filename"
    fi

    # Sleep for the interval
    if ((i < length - 1)); then
      sleep "$interval"
    fi
  done

  echo "Screenshot sequence complete!"
}

# Run the yad interface and capture user input
user_input=$(run_yad_interface)

if [[ $? -ne 0 ]]; then
  echo "Operation cancelled."
  exit 0
fi

# Parse user input
OUTPUT_DIR=$(echo "$user_input" | awk -F '|' '{print $1}')
INTERVAL=$(echo "$user_input" | awk -F '|' '{print $2}')
LENGTH=$(echo "$user_input" | awk -F '|' '{print $3}')
DATE_FORMAT=$(echo "$user_input" | awk -F '|' '{print $4}')
NOTIFY_ENABLED=$(echo "$user_input" | awk -F '|' '{print $5}')

# Validate output directory
if [[ ! -d "$OUTPUT_DIR" ]]; then
  mkdir -p "$OUTPUT_DIR"
  echo "Created directory: $OUTPUT_DIR"
fi

# Start taking screenshots
take_screenshots "$OUTPUT_DIR" "$INTERVAL" "$LENGTH" "$DATE_FORMAT" "$NOTIFY_ENABLED"

Similar Posts