Skip to content

Instantly share code, notes, and snippets.

@unhammer
Last active February 21, 2022 20:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save unhammer/2aa6b941b07ef7e9fb46f10bbcb9561f to your computer and use it in GitHub Desktop.
Save unhammer/2aa6b941b07ef7e9fb46f10bbcb9561f to your computer and use it in GitHub Desktop.
Launch Signal if not running, otherwise toggle hidden/shown state. Put signal.desktop in ~/.config/autostart/.
#!/bin/bash
run () {
signal-desktop &
disown
}
show () {
local -r id="$1"
idx="$(printf "0x%08x" "${id}")"
wmctrl -i -r "${idx}" -b remove,skip_taskbar,skip_pager
wmctrl -i -R "${idx}" # really make sure it's raised
xdotool windowraise "${id}"
}
hide () {
local -r id="$1"
idx="$(printf "0x%08x" "${id}")"
wmctrl -i -r "${idx}" -b add,skip_taskbar,skip_pager
xdotool windowminimize "${id}"
}
get_id () {
xdotool search --name '^Signal( \([0-9]+\))?$'
}
missing=false
if ! command -V wmctrl >/dev/null; then
echo "Please install wmctrl"
missing=true
fi
if ! command -V xdotool >/dev/null; then
echo "Please install xdotool"
missing=true
fi
if ! command -V xprop >/dev/null; then
echo "Please install x11-utils"
missing=true
fi
if "${missing}"; then exit 1; fi
if ! id="$(get_id)"; then
run
if [[ $1 = hide ]]; then
for i in {1..20}; do
if id="$(get_id)"; then hide "${id}"; break; fi
sleep 0.5
done
fi
else
if xprop -id "${id}" | grep -q '^_NET_WM_STATE(ATOM) =.* _NET_WM_STATE_SKIP_PAGER'; then
show "${id}"
else
hide "${id}"
fi
fi
[Desktop Entry]
Encoding=UTF-8
Version=0.1.2
Type=Application
Name=Start Signal minimized or toggle
Comment=Start Signal Private Messenger and immediately hide it, or toggle if already running
Exec=/path/to/above/signal hide
StartupNotify=false
Terminal=false
Hidden=false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment