Skip to content

Instantly share code, notes, and snippets.

@jvalrog
Created November 6, 2018 19:44
Show Gist options
  • Save jvalrog/fcf7744f6997d4463577a5a5ab91c001 to your computer and use it in GitHub Desktop.
Save jvalrog/fcf7744f6997d4463577a5a5ab91c001 to your computer and use it in GitHub Desktop.
An i3-like scratchpad using xdotool
#!/bin/sh
#
# SCRATCHPAD
#
# An i3-like scratchpad using xdotool.
#
# Example:
# ~$ scratchpad htop-pad urxvt -T htop-pad -e htop
#
# Explanation:
# * If there is no window with title "htop-pad", a new
# urxvt terminal will be run with "htop-pad" as title and
# executing an htop instance.
#
# * If the window already exists (visible or not), its
# visibility will be toggled.
#
if [ $# -lt 2 ]; then
echo "usage: $(basename $0) <window title> <program>" >&2
exit 1
fi
title="$1"; shift; program="$@"
if ! wid=$(xdotool search --name "^$title$"); then
$program &
elif echo $wid | grep -q " "; then
echo "error: several windows matched." >&2
exit 1
else
if xdotool search --onlyvisible --name "^$title$" 2>&1 > /dev/null; then
xdotool windowunmap $wid
else
xdotool set_desktop_for_window $wid $(xdotool get_desktop) \
windowmap --sync $wid windowfocus $wid
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment