banovski

Animation assembler

Sep 28th, 2026 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.81 KB | Software | 0 0
  1. #!/bin/bash
  2.  
  3. # Monitors clipboard for PNG images and writes them as files. When stopped
  4. # turns the saved files into a GIF animation.
  5.  
  6. function is_installed()
  7. {
  8.     local app="$1"
  9.  
  10.     if command -v "$app" > /dev/null; then
  11.         return 0
  12.     else
  13.         return 1
  14.     fi
  15. }
  16.  
  17. function announce()
  18. {
  19.     local message="$1"
  20.  
  21.     if is_installed "espeak"; then
  22.         espeak -v "whisper" -s 300 "$message"
  23.     else
  24.         echo "$message"
  25.     fi
  26. }
  27.  
  28. function leave()
  29. {
  30.     local message="$1"
  31.     local exit_status="$2"
  32.  
  33.     announce "$message"
  34.     exit "$exit_status"
  35. }
  36.  
  37. for app in "xclip" "gio" "convert" "clipnotify" "play" "zenity"; do
  38.     if ! is_installed "$app"; then
  39.         leave "$app is not installed! Exiting!" 1
  40.     fi
  41. done
  42.  
  43. cd ~/Images || leave "Couldn't change the directory! Exiting!" 1
  44.  
  45. gio trash -f frame_*.png
  46.  
  47. echo -n | xclip -i -selection clipboard
  48.  
  49. script_PID="$$"
  50.  
  51. {
  52.     zenity                               \
  53.         --question                       \
  54.         --title="Animation assembler"    \
  55.         --text="Generate the animation?" \
  56.         --no-wrap                        \
  57.         --cancel-label='Abort'
  58.  
  59.     if [ "$?" -eq 0 ]; then
  60.         convert -quiet -delay 10 -loop 0 frame_*.png output.gif
  61.         announce "Done!"
  62.     else
  63.         announce "Aborted!"
  64.     fi
  65.     kill "$script_PID"
  66. } &
  67.  
  68. counter=0
  69.  
  70. while clipnotify -s clipboard; do
  71.     until xclip -o -selection clipboard -t TARGETS | grep "image/png"; do
  72.         sleep 0.3
  73.     done
  74.  
  75.     frame_number=$(printf "%03d" "$counter")
  76.     current_frame_path="frame_${frame_number}.png"
  77.     (( counter++ ))
  78.     xclip -o -selection clipboard -t image/png > "$current_frame_path" && \
  79.         play -n synth 0.1 sine 220 vol -20dB 2> /dev/null
  80.     echo -n | xclip -i -selection clipboard
  81. done
  82.  
Advertisement
Add Comment
Please, Sign In to add comment