PJ/find_or_open.sh
2025-07-02 09:02:46 -07:00

16 lines
410 B
Bash
Executable file

#!/bin/bash
find_or_open(){
windows=$(wmctrl -l)
if [[ "${windows,,}" == *"$1"* ]]; then
xdotool windowactivate "$(wmctrl -l | grep -i "$1" | cut -d " " -f 1)"
echo "found $1"
else
nohup "$1" >/dev/null 2>&1 &
echo "opening $1"
fi
}
# this can either be sourced by buttons.sh or run as a standalone script
if [ "${BASH_SOURCE[0]}" = "$0" ] && [[ -n $1 ]]; then
find_or_open "$1"
fi