Hi guys,
GREAT! Thank you Meanie and Antikx for wmctrl... just the tool which was missing!
Now I have written a script which does what I always looked for.
I wanted the application keys to be handled the way they are handled under Sharp/Cacko:
Push it to start the application.
Push it again when the app is running and it brings the window to the foreground.
VERY handy especially for calendar / address book etc!
Here are the relevant parts from my application wrapper script (call it "xlaunch" and let the application keys launch "xlaunch kopi" instead of just "kopi" etc.
Works great!
(since this is stripped from my huge wrapper script, I am not sure if this works as written here. But it sohuld at least give the idea and some implementation details):
I like these grep-awk-grep-awk pipes :-)
CODE
#!/bin/bash
ALLOWMOREINSTANCES=0
# Extract binary name from parameter:
BINARY=`echo "$1" | awk '{ print $1 }'`
BINARY=`basename "$BINARY"`
# Check if application already runs: (look for binary
# basename in ps x output column 5
ps x | grep -v "$0" | awk '{print $5}' | grep "$BINARY$" > /dev/null
if [ $? -ne 1 ]; then
# Program already runs. Bring it to foreground
# except if "ALLOWMOREINSTANCES" is set to 1 for the app.
echo $0: $1 is already running.
if [ $ALLOWMOREINSTANCES -eq 0 ]; then
BINPID=`ps x | grep -v "$0" | awk '{print $1 " " $5}' | grep "$BINARY$" | awk '{print $1}'`
echo DEBUG: PID of $BINARY is $BINPID.
BINWINID=`wmctrl -l -p | awk '{print $1 " " $3}' | grep " $BINPID$"`
echo DEBUG: BINWINID of $BINARY is $BINWINID
wmctrl -i -a "$BINWINID"
exit 0
fi
fi
#Start application:
echo $0: $1 is starting. Please wait...
$1
ERRCODE=$?
echo "($1)" exited with errorcode "$ERRCODE".
Now, I'd like to maximize all application windows by default after the app is started using the wrapper script.
Any idea how to do that?
CODE
wmctrl -i -r $BINWINID -b add,maximized_vert,maximized_horz
would do this (and does this, I have tested it), but the difficult part is to know when the window has been created and just after that do the maximize.
Some applications need a lot of time to generate their main window.
I thought of implementing a while loop with one pass per second which tests if there is already a window for the PID, and if there is, maximize it.
But maybe someone knows a more elegant solution?
Thanks
daniel