Created
May 9, 2017 10:31
-
-
Save cyphunk/96ac9885e317fd3cb0bfb34307b36c94 to your computer and use it in GitHub Desktop.
create a visor for file manager or other apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
# given a window name, toggle visability | |
# map this to a short cut key | |
# based on https://stackoverflow.com/questions/12056898/use-dolphin-or-other-browser-like-yakuake | |
# https://bbs.archlinux.org/viewtopic.php?id=71789&p=1 | |
command -v xdotool >/dev/null || echo "Error: install xdotool" | |
function usage () { | |
cat <<EOM | |
$0 <exec> [\"start_hidden\"] [<unfocus_timeout>]" | |
toggle or start xterm hidden in background, minimize after 0.1sec unfocus | |
$0 xterm start_hidden 0.1 | |
toggle or start xterm in foreground, minimize after 0.1sec unfocus | |
$0 xterm 0.1 | |
EOM | |
exit 1 | |
} | |
test -n "$1" || usage | |
CMD=$1; shift; | |
test "$1" = "start_hidden" && HIDE=1 && shift | |
TIMEOUT="$1" | |
# use xprop or xwininfo to get detail used in xdotool search | |
winid=$(xdotool search --classname "$CMD" 2>/dev/null |tail -1) | |
if test -z "$winid"; then | |
$CMD & | |
pid=$! | |
winid=$(xdotool search --sync --pid $pid 2>/dev/null | tail -1) | |
test -n "$HIDE" \ | |
&& xdotool windowminimize --sync $winid \ | |
|| (xdotool windowactivate --sync $winid && xdotool windowfocus --sync $winid) | |
else | |
isvisible=$(xdotool search --onlyvisible --classname $CMD) | |
if test -n "$isvisible"; then | |
xdotool windowminimize --sync $winid | |
else | |
xdotool windowactivate $winid && xdotool windowfocus --sync $winid | |
if test -n "$TIMEOUT"; then | |
while true; do | |
sleep $TIMEOUT | |
if [ "`xdotool getwindowfocus`" != "$winid" ]; then | |
xdotool windowminimize --sync $winid | |
break | |
fi | |
done | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment