I slightly modified the dl-progress script (which was for dzen) in order to get the same thing with zenity. The reason for this is basically that you can choose your destination folder, and the progress bar is bigger. Moreover, auto-opening is disabled by default, you can enable it easily by uncommenting the related parts.

The script is much simpler than dl-progress, because I'm no real programmer. Please feel free to improve it.

iosonofabio 2009/08/26 17:53

#!/bin/bash
#
# the original dget.sh script:
# (c) 2007 by Robert Manea
#
# bashtardized and heavily modded for uzbl:
# 2009 by pbrisbin
#
# modified for zenity
# 2009 by iosonofabio
#
# requires:
#   zenity
#   wget
#
###
#
# these are passed in from uzbl
PID="$2"
XID="$3"
URL="$8"
#
# auto open the file post-download based on the
# file's extension
# TODO: please people, add your own here and report them on
# the uzbl wiki page.  these are the ones i use, i'd love
# to have a more complete list
#
# It's worth mentionning that gnome-open would probably do the job.
#
#open() {
#  case "$1" in
#    *.pdf)                                      xpdf "$1" &      ;;
#    *.jpg|*.png|*.jpeg)                         mirage "$1" &        ;;
#    *.txt|*README*|*.pl|*.sh|*.py|*.hs)         urxvt -e vim "$1" & ;;
#    *.mov|*.avi|*.mpeg|*.mpg|*.flv|*.wmv|*.mp4) vlc "$1" &       ;;
#  esac
#}
#
# get filename from the url and convert some hex codes
# i hate spaces in filenames so i'm switching them
# with underscores here, adjust the first s///g if
# you want to keep the spaces
FILE="$(basename $URL | sed -r \
's/[_%]20/\_/g;s/[_%]22/\"/g;s/[_%]23/\#/g;s/[_%]24/\$/g;
s/[_%]25/\%/g;s/[_%]26/\&/g;s/[_%]28/\(/g;s/[_%]29/\)/g;
s/[_%]2C/\,/g;s/[_%]2D/\-/g;s/[_%]2E/\./g;s/[_%]2F/\//g;
s/[_%]3C/\</g;s/[_%]3D/\=/g;s/[_%]3E/\>/g;s/[_%]3F/\?/g;
s/[_%]40/\@/g;s/[_%]5B/\[/g;s/[_%]5C/\\/g;s/[_%]5D/\]/g;
s/[_%]5E/\^/g;s/[_%]5F/\_/g;s/[_%]60/\`/g;s/[_%]7B/\{/g;
s/[_%]7C/\|/g;s/[_%]7D/\}/g;s/[_%]7E/\~/g;s/[_%]2B/\+/g')"
#
# show zenity directory selection window to ask the user
# for the destination folder. Wait until the user answers
# for beginning download (this could be improved).
DIRFILE=$(zenity --file-selection --save --filename="$FILE" --confirm-overwrite)
# download
[ "$DIRFILE" ] && wget -O "$DIRFILE" --user-agent=Firefox "$URL" 2>&1 | sed -u 's/^[a-zA-Z\-].*//; s/.* \{1,2\}\([0-9]\{1,3\}\)%.*/\1\n#Downloading... \1%/; s/^20[0-9][0-9].*/#Done./' | zenity --progress --percentage=0 --title="Download dialog" --text="Starting..." &
pid=$!
#
# finally, auto-open the downloaded file
#[ $? -eq 0 ] && open "$DIRFILE"
#
exit 0
 
dl-progress-zenity.txt · Last modified: 2009/09/23 16:46 by chm.duquesne
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki