Copy Link
Add to Bookmark
Report
NULL mag Issue 08 19 Autorun downloaded files
one feature of all modern browsers, is that while you download a file
they let you choose to open the file or just save it. this is very
helpful specially when you want to read/listen/view something "on the
fly" the moment you download it.
i have made this request in the past, publicly... i think from here,
but i don't suppose that will see it embedded, very soon in any telnet
client. so i made my own version... kinda... that resembles this
functionality.
first of all... it's for linux! windows users you can keep reading the
other articles in here :p second, you have to install the packages
"zenity" and "inotify-tools". if you don't know how... you are also
outta here... :p
third... copy/paste the following script and make it executable. you
have to start this script, every time you run your telnet client and
let it run in the background. my favorite client is Netrunner, so i
made another script to launch both Netrunner and the "watch" script.
you can find it in the bottom.
you must setup your client to download files in the same directory the
"watchdir" script does. you can configure the watchdir script with an
editor to do that. you can also change other things.
as you can see the watchdir script detects newly created files in the
specified directory. it gets the extension of that file and if it
matches one of our categories (ansi, music, text, archive) executes
the specified program to view/listen the file. it uses the zenity
dialogs to ask you first, if you want to launch the viewer, in case
you don't.
it's a very cool feature to add and at least, personally, it helps me
a lot while visiting BBSes. hope you like it and use it a lot.
---- watchdir.sh --------------------------------------------------------
#!/bin/bash
musictype="MOD;S3M;IT;XM"
ansitype="ANS;ASC;DIZ"
texttype="TXT;DOC"
archives="ZIP;RAR;7Z;TAR"
musicplayer="audacious"
ansiviewer="xansiviewer"
zipviewer="file-roller"
textviewer="geany"
$downloaddir="/home/user/Downloads"
inotifywait -m $downloaddir -e create -e moved_to |
while read filepath action file; do
#echo "The file '$file' appeared in directory '$filepath' via '$action'"
# do something with the file
extension="${file##*.}"
filename="${file%.*}"
ext="${extension^^}"
if grep -q "$ext" <<<"$musictype"; then
zenity --question --text "Play file: $file ?"
if [ $? = 0 ]; then
nohup $musicplayer "$filepath$file" &
fi
fi
if grep -q "$ext" <<<"$ansitype"; then
zenity --question --text "View file: $file ?"
if [ $? = 0 ]; then
nohup $ansiviewer "$filepath$file" &
fi
fi
if grep -q "$ext" <<<"$archives"; then
zenity --question --text "View file: $file ?"
if [ $? = 0 ]; then
nohup $zipviewer "$filepath$file" &
fi
fi
if grep -q "$ext" <<<"$texttype"; then
zenity --question --text "View file: $file ?"
if [ $? = 0 ]; then
nohup $textviewer "$filepath$file" &
fi
fi
done
-------------------------------------------------------------------------
---- netrunner.sh -------------------------------------------------------
#!/bin/bash
pcd=$(pwd)
/home/user/scripts/watch_bbs_dir.sh &
cd /home/user/bin/netrunner
./netrunner
cd "$pcd"
-------------------------------------------------------------------------
<<< null e-magazine x008 (text edition) >>>
____ _____ _____ _____ http://github.com/xqtr/null
___/. \/ /_________/. /__/. /__jp!_ andr01d.zapto.org:9999
//_ \ . / / \ / _// agency.bbs.nz
/____/\____/ / /__________________\ d1st.org
\________/