You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
911 B
Bash

#!/bin/bash
# usage:
# raisewindow firefox
#
# or, if the binary and window class are dissimilar:
# raisewindow firefox-developer firefox
# ^binary name ^ partial class name of windows created by this application (xprop)
CMD=$1
if [ -n "$2" ]; then
CLASS=$2
else
CLASS=$CMD
fi
function gshell(){
gdbus call \
--session \
--dest org.gnome.Shell \
--object-path /org/gnome/Shell \
--method org.gnome.Shell.Eval "$1" \
| sed -E -e "s/^\(\S+, '//" -e "s/'\)$//"
}
if [[ $XDG_SESSION_TYPE = "wayland" ]]; then
RESP=`gshell "
global
.get_window_actors()
.filter(w=>w.meta_window.get_wm_class().toLowerCase()==\"$CLASS\".toLowerCase())[0].meta_window.activate(0)"`
if [[ "$RESP" == *undefined ]]; then
$CMD;
fi
else
wmctrl -x -a "$CLASS" || ($CMD & notify-send -i "$CLASS" "Starting $CMD");
fi