Last active
December 10, 2015 11:59
-
-
Save umrysh/4431358 to your computer and use it in GitHub Desktop.
A modified version of the "start_on_desktop" script posted at: http://superuser.com/questions/236526/how-to-open-a-program-on-particular-desktop/236629#236629
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/sh | |
if test $# -lt 2 | |
then | |
echo "Usage: start_on_desktop <desktop> <command> [<command args>...]" 1>&2 | |
exit 2 | |
fi | |
desktop=$(($1-1)) # Dave: Let the user specify the Desktop starting at 1, not 0 | |
if [ "$2" == "subl" ] # Dave: Helpful tip for running Sublime-Text | |
then | |
sublime=`cat /usr/bin/subl | grep 'sublime_text' | cut -d ' ' -f1 | cut -d '=' -f2` | |
echo 'Sublime-Text: Run with "'$sublime'" instead of "subl".' 1>&2 | |
exit 2 | |
fi | |
shift | |
"$@" > /dev/null 2>&1 & # Dave: Added the "> /dev/null 2>&1" | |
pid=$! | |
tries=100 | |
sleeptime=0.1 | |
while test $tries -gt 0 | |
do | |
sleep $sleeptime | |
windows=$(wmctrl -l -p) | |
while read _id _desktop _pid _rest | |
do | |
if (($_pid != 0)) # Dave: "error: process ID out of range" test | |
then | |
_ppid=$(ps -o ppid= -p $_pid) | |
if [[ -z "$_ppid" ]] # Dave: Check for NULL | |
then | |
_ppid=0 | |
fi | |
# Dave: New Conditional Statement | |
if (("$_pid" == "$pid" || "$_ppid" == "$pid")) | |
then | |
id=$_id | |
break 2 | |
fi | |
fi | |
done <<EOF | |
$windows | |
EOF | |
tries=$((tries - 1)) | |
done | |
if test -n "$id" | |
then | |
wmctrl -i -r "$id" -t "$desktop" | |
exit $? | |
else | |
echo "Window not found" 1>&2 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment