Topic: Script to quickly mount/unmount an iso file
I got tired of typing the same stuff in a terminal over and over, so put this script together to add to Thunar's custom actions.
If you are looking at .iso files a lot it might be handy. It will make a folder in the current directory, mount the iso file to it (with gksu) and open thunar in that folder. If the iso is mounted already it will unmount it. The folder is deleted once you've unmounted it. You won't be able to edit the iso file, just view it, or copy stuff out of it. edit - unmounted folder deleted, and added some checks
#!/bin/bash
# open-iso.sh
# mount .iso file in new folder and open with thunar, unmount if mounted already
[[ -f $1 ]] && [[ $1 = *.iso ]] || { notify-send "$1 is not an iso file"; exit 1 ;}
foldername=${1%.iso}
if grep "^/dev/loop.*$(readlink -f $foldername)" /etc/mtab >/dev/null
then
gksu --description "open-iso (unmount)" "umount $foldername" || { notify-send "failed to unmount $1"; exit 1;}
notify-send "$1 has been unmounted"
[[ -d $foldername ]] && [[ -z $( ls -A $foldername ) ]] && rm -r $foldername # only remove folder if it is empty
else
[[ -d $foldername ]] && [[ $( ls -A $foldername ) ]] && { notify-send "$foldername is not empty" ; exit 1 ;}
mkdir -p $foldername || { notify-send "Could not create folder $foldername"; exit 1;}
gksu --description "open-iso (mount)" "mount -o loop $1 $foldername" || { notify-send "failed to mount $1"; exit 1;}
thunar $foldername
fi
exitAs usual, put it in ~/scripts or somewhere handy and add a custom action like '~/scripts/open-iso.sh %f'. Make the appearance conditions "Other Files" and File pattern '*.iso'.
Last edited by johnraff (2010-03-05 18:02:24)
------------------------
( a boring Japan blog , and idle twitterings )
“There is more Unix-nature in one line of shell script than there is in ten thousand lines of C.” - Master Foo