Skip to content

Instantly share code, notes, and snippets.

@LC43
Last active November 25, 2017 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LC43/883d34f0c9ca1cebc0206ca9a73ecb09 to your computer and use it in GitHub Desktop.
Save LC43/883d34f0c9ca1cebc0206ca9a73ecb09 to your computer and use it in GitHub Desktop.
Raise window by name
#!/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