Created
May 28, 2012 17:43
-
-
Save atondwal/2820258 to your computer and use it in GitHub Desktop.
spawn application in nth desktop
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/zsh | |
################################################## | |
# Get application's window ID | |
# Input: | |
# $1: application's process ID | |
# Output: | |
# $1: application's window ID | |
# Return value: | |
# success: 0 | |
# failed: 1 | |
# Usage: | |
# ID=`WID $PID` | |
# | |
#these apps use a separate process to make a window) | |
bad=(chromium chromium-browser) | |
WID() { | |
APP=`ps --no-header -o comm -p $1` | |
# Loop windows with application's executable name | |
while read WID; do | |
WID=`echo $WID | awk '{print $1}'` | |
# Check window's PID is matching application's PID | |
if [ `xprop -id $WID _NET_WM_PID | awk '{print $3}'` -eq $1 -o \ | |
`xprop -id $WID WM_CLASS | awk '{print $3}' | cut -d\" -f2` = $APP -a ${bad[(i)$APP]} -le ${#bad} ] ; then | |
# Check is actual visible window | |
if [ "`xwininfo -id $WID | \ | |
grep 'IsViewable'`" != '' ] ; then | |
echo $WID | |
return 0 | |
fi | |
fi | |
done < <( xwininfo -root -children 2>/dev/null | grep $APP ) | |
return 1 | |
} | |
if [ $# -lt 2 -o $# -gt 3 ] | |
then | |
echo "Usage: "$0" cmd tag [sleep]" | |
exit | |
fi | |
$1 & | |
PID=$! | |
#echo $PID | |
#wait for the app to launch | |
until WID $PID | |
do | |
sleep .2 | |
done | |
wmctrl -i -r `WID $PID` -t $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment