Skip to content

Instantly share code, notes, and snippets.

@edwinclement08
Created April 30, 2021 19:12
Show Gist options
  • Save edwinclement08/1b02b9ad6a778caab260ddd3cfd1759e to your computer and use it in GitHub Desktop.
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)
#!/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
@cocoonkid
Copy link

It starts Alacritty but it always opens up a new terminal, not the same one.

@cocoonkid
Copy link

I made it work with hhttps://github.com/noctuid/tdrop

@edwinclement08
Copy link
Author

Interesting. Will check out the behaviour the next time I use Arch.

@danielclough
Copy link

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