Created
April 30, 2021 19:12
-
-
Save edwinclement08/1b02b9ad6a778caab260ddd3cfd1759e to your computer and use it in GitHub Desktop.
Simple Script that can hide/focus or start an app(useful with alacritty)
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/sh | |
if [ $# -ne 2 ] | |
then | |
echo "Pass 2 params" | |
echo -e "show_app.sh <Window Title to check for> <app to open>" | |
echo -e "\nNotes\n\t<Window url> should be an exact string match" | |
echo -e "\t<app to open> should be path to the executable" | |
exit | |
fi | |
AWK_STRING="{ if (\$4 == \"$1\") print \$1 }" | |
PROGRAM_WINDOW_ID=`wmctrl -l | tr -s ' ' | awk "$AWK_STRING" ` | |
if [ ${#PROGRAM_WINDOW_ID} -gt 0 ]; | |
then | |
xprop -id $PROGRAM_WINDOW_ID | grep _NET_WM_STATE_FOCUSED 1>/dev/null | |
if [ $? -eq 0 ]; | |
then | |
echo "Focused->Hidden"; | |
wmctrl -F -i -r "$PROGRAM_WINDOW_ID" -b toggle,hidden | |
else | |
echo "Hidden/Unfocused->Focused" | |
wmctrl -F -a "Alacritty" | |
fi | |
echo ${#string} | |
else | |
echo "Starting Alacritty"; | |
sh -c $2 & | |
fi |
Interesting. Will check out the behaviour the next time I use Arch.
It starts Alacritty but it always opens up a new terminal, not the same one.
I had this issue before I noticed that wmctrl
is a dependency, after installing it works fine.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I made it work with hhttps://github.com/noctuid/tdrop