Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Monitors clipboard for PNG images and writes them as files. When stopped
- # turns the saved files into a GIF animation.
- function is_installed()
- {
- local app="$1"
- if command -v "$app" > /dev/null; then
- return 0
- else
- return 1
- fi
- }
- function announce()
- {
- local message="$1"
- if is_installed "espeak"; then
- espeak -v "whisper" -s 300 "$message"
- else
- echo "$message"
- fi
- }
- function leave()
- {
- local message="$1"
- local exit_status="$2"
- announce "$message"
- exit "$exit_status"
- }
- for app in "xclip" "gio" "convert" "clipnotify" "play" "zenity"; do
- if ! is_installed "$app"; then
- leave "$app is not installed! Exiting!" 1
- fi
- done
- cd ~/Images || leave "Couldn't change the directory! Exiting!" 1
- gio trash -f frame_*.png
- echo -n | xclip -i -selection clipboard
- script_PID="$$"
- {
- zenity \
- --question \
- --title="Animation assembler" \
- --text="Generate the animation?" \
- --no-wrap \
- --cancel-label='Abort'
- if [ "$?" -eq 0 ]; then
- convert -quiet -delay 10 -loop 0 frame_*.png output.gif
- announce "Done!"
- else
- announce "Aborted!"
- fi
- kill "$script_PID"
- } &
- counter=0
- while clipnotify -s clipboard; do
- until xclip -o -selection clipboard -t TARGETS | grep "image/png"; do
- sleep 0.3
- done
- frame_number=$(printf "%03d" "$counter")
- current_frame_path="frame_${frame_number}.png"
- (( counter++ ))
- xclip -o -selection clipboard -t image/png > "$current_frame_path" && \
- play -n synth 0.1 sine 220 vol -20dB 2> /dev/null
- echo -n | xclip -i -selection clipboard
- done
Advertisement
Add Comment
Please, Sign In to add comment