Skip to content

Instantly share code, notes, and snippets.

@qguv
Last active September 25, 2015 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qguv/839618 to your computer and use it in GitHub Desktop.
Save qguv/839618 to your computer and use it in GitHub Desktop.
simple timer using zenity
#! /bin/bash
# Timed unlock script. Must be run as root.
input=$(zenity --entry --text="Enter directory to be unlocked.")
name="$input"
thetime="5"
unit="m"
(
counter=0
while [ "$counter" -le 100 ]; do
echo $counter; sleep "${increasefactor}""${unit}"
counter=$(( $counter + 1 ))
done
) |
zenity --progress --title="$name" --text="File opened. Open for 5 minutes." --percentage=0 --auto-close &&
sudo chmod -R 770 "$input"
if [ "$?" == 1 ]; then
zenity --info --width=350 --title="$name" --text="File access closed before timeout."
else
zenity --info --width=350 --title="$name" --text="File access timed out."
fi
increasefactor=$(echo "${thetime}"/100|bc -l)
sudo chmod -R 777 "$input"
(
counter=0
while [ "$counter" -le 100 ]; do
echo $counter; sleep "${increasefactor}""${unit}"
counter=$(( $counter + 1 ))
done
) |
zenity --progress --title="$name" --text="File opened. Open for 5 minutes." --percentage=0 --auto-close &&
#sudo chmod -R 770 "$input"
if [ "$?" = "1" ]; then
zenity --info --width=350 --title="$name" --text="File access closed before timeout."
else
zenity --info --width=350 --title="$name" --text="File access timed out."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment