Last active
November 25, 2017 06:46
-
-
Save LC43/883d34f0c9ca1cebc0206ca9a73ecb09 to your computer and use it in GitHub Desktop.
Raise window by name
This file contains hidden or 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/bash | |
# name of app | |
if [ -z "$1" ]; then | |
echo "provide a name for the window to be raised" | |
exit; | |
fi | |
app_name="$1" | |
# get current desktop: | |
desktop_id=$(xprop -root | grep "^_NET_CURRENT_DESKTOP" | cut -f 3 -d ' ') | |
if [ -z "$desktop_id" ]; then | |
echo "Couldn't find desktop id" | |
exit; | |
fi | |
# find windows in current desktop: $desktop_id | |
app_list=$(wmctrl -xl | awk -v id="${desktop_id}" -F' ' '$2==id' | awk '{print $1,$3}' ) | |
if [ -z "$app_list" ]; then | |
echo "No windows on this desktop" | |
exit; | |
fi | |
# find window to raise | |
app_id=$(echo "$app_list" | grep -i "$app_name" | cut -d ' ' -f 1 ) | |
if [ -z "$app_id" ]; then | |
echo "Couldn't find this app: $app_name; launching..." | |
$($app_name) & | |
exit; | |
fi | |
wmctrl -ia "$app_id" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment