Skip to content

Instantly share code, notes, and snippets.

@swarminglogic
Last active May 9, 2016 15:55
Show Gist options
  • Save swarminglogic/def93e17d80bbbf858b2 to your computer and use it in GitHub Desktop.
Save swarminglogic/def93e17d80bbbf858b2 to your computer and use it in GitHub Desktop.
Fills out username/password. Triggered by global hotkey. Application agnostic. Determines best user/pass match from process information. Requiers userpass.sh (https://gist.github.com/swarminglogic/40922ce92e49aae3b2ca)
#!/bin/bash
# Use this with a global hotkey to the following: gksudo [FULLPATH]/enterpass.sh
if [[ $EUID -ne 0 ]] ; then
notify-send "This script must be run as root"
exit
fi
if ! command -v userpass > /dev/null ; then
notify-send "Could not find userpass utility"
exit
fi
activeWindow=$(xdotool getactivewindow)
pid=$(xprop -id $activeWindow | grep _NET_WM_PID | cut -d' ' -f3)
process=$(ps --pid=$pid h -o "%c")
windowTitle=$(xwininfo -id $activeWindow | grep "xwininfo: Window id:" |\
grep -oP '".*' | sed 's/^"//g;s/"$//g;s/://g')
# Do application specific operations
# (for browsers, remove process name from title. For terminals, substitute tab with enter)
chrome=chrome
firefox=firefox
opera=opera
terminal=gnome-terminal
if [ ! "${process/$chrome}" = "$process" ] ; then
windowTitle=`echo $windowTitle | sed -s "s/Google Chrome$//g"`
elif [ ! "${process/$firefox}" = "$process" ] ; then
windowTitle=`echo $windowTitle | sed -s "s/Mozilla Firefox$//g"`
elif [ ! "${process/$opera}" = "$process" ] ; then
windowTitle=`echo $windowTitle | sed -s "s/Opera$//g"`
elif [ ! "${process/$terminal}" = "$terminal" ] ; then
useReturnAsTab=yes
fi
entry=$(userpass --script-mode -m "$windowTitle")
if [[ ! $entry ]] ; then
site=$(zenity --text "Enter website keyword:" --entry)
entry=$(userpass --script-mode -m "$site")
xdotool windowactivate $activeWindow
fi
if [[ $entry ]] ; then
username=$(userpass --script-mode $entry -u)
password=$(userpass --script-mode $entry -p)
xdotool type --delay 30 "$username"
[[ $useReturnAsTab ]] && xdotool key Return || xdotool key Tab
sleep 0.2
xdotool type --delay 30 "$password"
sleep 0.2
else
notify-send "Password not found"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment