Author Topic: Is There A Command Line Utility  (Read 2786 times)

Meanie

  • Hero Member
  • *****
  • Posts: 2803
    • View Profile
    • http://www.users.on.net/~hluc/myZaurus/
Is There A Command Line Utility
« on: March 14, 2007, 07:28:52 pm »
before i attempt to write one of my own, is there a utility that can bring a running application such as xmms to the foreground?

what i want to do is to send xmms to the foreground if it its running when closing the Z's display. this would then allow me to control the music using the ok and slider on the back of the zaurus.

currently i need to alt tab it to the foreground before closing the display. i want to automate that
SL-C3000 - pdaXii13 build5.4.9 (based on pdaXrom beta3) / SL-C3100 - Sharp ROM 1.02 JP (heavily customised)
Netgear MA701 CF, SanDisk ConnectPlus CF, Socket Bluetooth CF, 4GB Kingston CF,  4GB pqi SD, 4GB ChoiceOnly SD, 2GB SanDisk SD USB Plus, 1GB SanDisk USB Plus, 1GB Transcend SD, 2GB SanDisk MicroSD with SD adaptor, Piel Frama Leather Case, GoldX 5-in-1 USB cable, USB hub, USB mouse, USB keyboard, USB ethernet, USB HDD, many other USB accessories...
(Zaurus SL-C3000 owner since March 14. 2005, Zaurus SL-C3100 owner since September 21. 2005)
http://members.iinet.net.au/~wyso/myZaurus - zBook3K

Meanie

  • Hero Member
  • *****
  • Posts: 2803
    • View Profile
    • http://www.users.on.net/~hluc/myZaurus/
Is There A Command Line Utility
« Reply #1 on: March 15, 2007, 12:40:27 am »
never mind, I wrote a small utility called xraise to do that
SL-C3000 - pdaXii13 build5.4.9 (based on pdaXrom beta3) / SL-C3100 - Sharp ROM 1.02 JP (heavily customised)
Netgear MA701 CF, SanDisk ConnectPlus CF, Socket Bluetooth CF, 4GB Kingston CF,  4GB pqi SD, 4GB ChoiceOnly SD, 2GB SanDisk SD USB Plus, 1GB SanDisk USB Plus, 1GB Transcend SD, 2GB SanDisk MicroSD with SD adaptor, Piel Frama Leather Case, GoldX 5-in-1 USB cable, USB hub, USB mouse, USB keyboard, USB ethernet, USB HDD, many other USB accessories...
(Zaurus SL-C3000 owner since March 14. 2005, Zaurus SL-C3100 owner since September 21. 2005)
http://members.iinet.net.au/~wyso/myZaurus - zBook3K

desertrat

  • Hero Member
  • *****
  • Posts: 743
    • View Profile
    • http://
Is There A Command Line Utility
« Reply #2 on: March 15, 2007, 01:17:39 am »
Quote
never mind, I wrote a small utility called xraise to do that
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156352\"][{POST_SNAPBACK}][/a][/div]
Any chance of extending it so that it will check whether an app is running, if so bring to front, if not start it?
« Last Edit: March 15, 2007, 01:18:25 am by desertrat »
SL-C3100 / Ambicon WL1100C-CF / pdaXrom 1.1.0beta3 / IceWM

Meanie

  • Hero Member
  • *****
  • Posts: 2803
    • View Profile
    • http://www.users.on.net/~hluc/myZaurus/
Is There A Command Line Utility
« Reply #3 on: March 15, 2007, 01:21:31 am »
Quote
Quote
never mind, I wrote a small utility called xraise to do that
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156352\"][{POST_SNAPBACK}][/a][/div]
Any chance of extending it so that it will check whether an app is running, if so bring to front, if not start it?
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156356\"][{POST_SNAPBACK}][/a][/div]

that could be possible, but the problem is that the executable name and the window name are not always the same, ie for xmms, the binary is xmms, but the window name is XMMS. For leafpad, the binary is leafpad, but the window name is (Untitled)  

it would probably be easier just to write a wrapper script say xlaunch which does a pidof to check if an app (the executable name) is running and if not, execute it, but if it is running, then use xwininfo -root -tree and parse the output to determine the window name of the running app and then use xraise to bring that window to the foreground...
« Last Edit: March 15, 2007, 01:24:55 am by Meanie »
SL-C3000 - pdaXii13 build5.4.9 (based on pdaXrom beta3) / SL-C3100 - Sharp ROM 1.02 JP (heavily customised)
Netgear MA701 CF, SanDisk ConnectPlus CF, Socket Bluetooth CF, 4GB Kingston CF,  4GB pqi SD, 4GB ChoiceOnly SD, 2GB SanDisk SD USB Plus, 1GB SanDisk USB Plus, 1GB Transcend SD, 2GB SanDisk MicroSD with SD adaptor, Piel Frama Leather Case, GoldX 5-in-1 USB cable, USB hub, USB mouse, USB keyboard, USB ethernet, USB HDD, many other USB accessories...
(Zaurus SL-C3000 owner since March 14. 2005, Zaurus SL-C3100 owner since September 21. 2005)
http://members.iinet.net.au/~wyso/myZaurus - zBook3K

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Is There A Command Line Utility
« Reply #4 on: March 15, 2007, 05:29:26 am »
Hi Meanie,

Such an xlaunch can look like this (I already wrote such a wrapper, but it is highly customized and huge, so I only post the general stuff here which is relevant to the thread):

Code: [Select]
#!/bin/bash

# Extract binary name from parameter:
BINARY=`echo "$1" | awk '{ print $1 }'`
BINARY=`basename "$BINARY"`

# Start $1 only if it does not run yet:
ps x | grep -v "$0" | awk '{print $5}' | grep "$BINARY$" > /dev/null
if  [ $? -ne 1 ]; then
  echo $1 is already running!
else
  $1
fi

If you call this script "xlaunch" then you can run e.g. "xlaunch kopi" and kopi will only be started if it is not running yet.
The binary extraction also allows that you call a program with path and parameters:

xlaunch "/opt/some/binary --withparameter1 --andevenmore"

So now, how can we determine the window name from the process name in order to marry xlaunch with xraise?

daniel
« Last Edit: March 15, 2007, 05:30:24 am by daniel3000 »
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0

cmpayc13

  • Newbie
  • *
  • Posts: 18
    • View Profile
Is There A Command Line Utility
« Reply #5 on: March 15, 2007, 05:47:06 am »
Is there a reason, You can not use xmmscontrol?
In this case, it is no matter, if the xmms-window is in foreground or not.

Best regards

cmpayc

Meanie

  • Hero Member
  • *****
  • Posts: 2803
    • View Profile
    • http://www.users.on.net/~hluc/myZaurus/
Is There A Command Line Utility
« Reply #6 on: March 15, 2007, 07:08:39 am »
Quote
Is there a reason, You can not use xmmscontrol?
In this case, it is no matter, if the xmms-window is in foreground or not.

Best regards

cmpayc
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156379\"][{POST_SNAPBACK}][/a][/div]

xmmscontrol which is by default configured in openbox causes the Z to almost lock up since it causes xmms to spawn too many instances which the Z cannot keep up with...

besides, this is just one use for xraise
SL-C3000 - pdaXii13 build5.4.9 (based on pdaXrom beta3) / SL-C3100 - Sharp ROM 1.02 JP (heavily customised)
Netgear MA701 CF, SanDisk ConnectPlus CF, Socket Bluetooth CF, 4GB Kingston CF,  4GB pqi SD, 4GB ChoiceOnly SD, 2GB SanDisk SD USB Plus, 1GB SanDisk USB Plus, 1GB Transcend SD, 2GB SanDisk MicroSD with SD adaptor, Piel Frama Leather Case, GoldX 5-in-1 USB cable, USB hub, USB mouse, USB keyboard, USB ethernet, USB HDD, many other USB accessories...
(Zaurus SL-C3000 owner since March 14. 2005, Zaurus SL-C3100 owner since September 21. 2005)
http://members.iinet.net.au/~wyso/myZaurus - zBook3K

desertrat

  • Hero Member
  • *****
  • Posts: 743
    • View Profile
    • http://
Is There A Command Line Utility
« Reply #7 on: March 15, 2007, 07:54:44 am »
Quote
So now, how can we determine the window name from the process name in order to marry xlaunch with xraise?
In my case I only need it for a few specific apps: eg sylpheed-claws, kopi, kapi, pwmanager etc, so for me maybe hardcoding it would be the easiest way.
SL-C3100 / Ambicon WL1100C-CF / pdaXrom 1.1.0beta3 / IceWM

Antikx

  • Hero Member
  • *****
  • Posts: 1147
    • View Profile
    • http://tyrannozaurus.com
Is There A Command Line Utility
« Reply #8 on: March 15, 2007, 08:10:43 am »
just an fyi, someone from the unix users group here responded to your orig question with:
Quote
how about dbus-send or ... eesh ?  depending upon your
wm... and yeah .. it would have to be wm specific ... at least afaik
Kanpai,
-Antikx (Twitter, Mugshot and PodNova)
C1000 - pdaXrom R198 (Celestial Environment)
tyrannozaurus.com
[img]http://www.tyrannozaurus.com/files/category_pictures/general_1.png\" border=\"0\" class=\"linked-sig-image\" /]
Zaurus news/blogs feed from Zaurus users
Free Windows, Linux, or Web RSS readers.
Featured pages at tyrannozaurus:
Sharp Petition, ScummVM, Cacko, pdaXii13, and Celestial Environment

Meanie

  • Hero Member
  • *****
  • Posts: 2803
    • View Profile
    • http://www.users.on.net/~hluc/myZaurus/
Is There A Command Line Utility
« Reply #9 on: March 15, 2007, 08:18:31 am »
Quote
Quote
So now, how can we determine the window name from the process name in order to marry xlaunch with xraise?
In my case I only need it for a few specific apps: eg sylpheed-claws, kopi, kapi, pwmanager etc, so for me maybe hardcoding it would be the easiest way.
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156387\"][{POST_SNAPBACK}][/a][/div]

xwininfo -root -tree |grep -i appname
some smart parsing of the results from the above and then pass the result to xraise


eventually, xlaunch will:

check if app is running or not
if running use xwininfo or other method to determine app window name and use that with xraise to bring it to foreground
if not running, start app. launch fancy looking splash/throbber window
use xresizewindow to maximize app using same info (xwininfo) as was used for xraise

optionally, xlaunch can also disable dpms and restore settings when finished
also optionally, xlaunch can stop the volume applet and restart it after app has finished in case the app needs the mixer
SL-C3000 - pdaXii13 build5.4.9 (based on pdaXrom beta3) / SL-C3100 - Sharp ROM 1.02 JP (heavily customised)
Netgear MA701 CF, SanDisk ConnectPlus CF, Socket Bluetooth CF, 4GB Kingston CF,  4GB pqi SD, 4GB ChoiceOnly SD, 2GB SanDisk SD USB Plus, 1GB SanDisk USB Plus, 1GB Transcend SD, 2GB SanDisk MicroSD with SD adaptor, Piel Frama Leather Case, GoldX 5-in-1 USB cable, USB hub, USB mouse, USB keyboard, USB ethernet, USB HDD, many other USB accessories...
(Zaurus SL-C3000 owner since March 14. 2005, Zaurus SL-C3100 owner since September 21. 2005)
http://members.iinet.net.au/~wyso/myZaurus - zBook3K

grog

  • Hero Member
  • *****
  • Posts: 692
    • View Profile
    • http://
Is There A Command Line Utility
« Reply #10 on: March 15, 2007, 10:59:26 am »
Pretty neat. How about a corresponding xlower utility?
GROG!

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Is There A Command Line Utility
« Reply #11 on: March 15, 2007, 11:32:08 am »
Quote
Quote
In my case I only need it for a few specific apps: eg sylpheed-claws, kopi, kapi, pwmanager etc, so for me maybe hardcoding it would be the easiest way.
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156387\"][{POST_SNAPBACK}][/a][/div]

xwininfo -root -tree |grep -i appname
some smart parsing of the results from the above and then pass the result to xraise



the parsing would have to be smart indeed. grepping for kopi shows a LOT of lines...

desertrat: Hardcoding is difficult, because some apps change their window name depending on window content (kopi for example changes heavily, but also many other apps which print the name of the opened file into the title).


I'll think about this smart parsing, but first I'll have to understand the output myself  

daniel
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0

Antikx

  • Hero Member
  • *****
  • Posts: 1147
    • View Profile
    • http://tyrannozaurus.com
Is There A Command Line Utility
« Reply #12 on: March 15, 2007, 04:31:16 pm »
and if it's of interest someone posted this:
Quote
I think what you're looking for is wmctrl:

Description: control an EWMH/NetWM compatible X Window Manager
 Wmctrl is a command line tool to interact with an EWMH/NetWM compatible X
 Window Manager (examples include Enlightenment, icewm, kwin, metacity,
 and sawfish).

 Wmctrl provides command line access to almost all the features defined in the
 EWMH specification. For example it can maximize windows, make them sticky, set
 them to be always on top. It can switch and resize desktops and perform many
 other useful operations.

For instance, on my currently running desktop:

oin$ wmctrl -l
0x00c00003 -1 oin Top Panel
0x00c0002d -1 oin Bottom Panel
0x00e00021 -1 oin Desktop
0x0280001f  0 oin root@gto: ~
0x02800f75  1 oin root@lemans: ~
0x02802735  2 oin Terminal
0x02600023  3 oin Holly Cole - I Will Wait for You
0x02a00020  2 oin linux icccm raise command - Google Search
0x028048a9  0 oin root@oin: ~

To switch my current screen to RhythmBox, and raise it to foreground:

oin$ wmctrl -a "Holly Cole - I Will Wait for You"
Kanpai,
-Antikx (Twitter, Mugshot and PodNova)
C1000 - pdaXrom R198 (Celestial Environment)
tyrannozaurus.com
[img]http://www.tyrannozaurus.com/files/category_pictures/general_1.png\" border=\"0\" class=\"linked-sig-image\" /]
Zaurus news/blogs feed from Zaurus users
Free Windows, Linux, or Web RSS readers.
Featured pages at tyrannozaurus:
Sharp Petition, ScummVM, Cacko, pdaXii13, and Celestial Environment

Meanie

  • Hero Member
  • *****
  • Posts: 2803
    • View Profile
    • http://www.users.on.net/~hluc/myZaurus/
Is There A Command Line Utility
« Reply #13 on: March 15, 2007, 07:45:34 pm »
Quote
and if it's of interest someone posted this:
Quote
I think what you're looking for is wmctrl:

Description: control an EWMH/NetWM compatible X Window Manager
 Wmctrl is a command line tool to interact with an EWMH/NetWM compatible X
 Window Manager (examples include Enlightenment, icewm, kwin, metacity,
 and sawfish).

 Wmctrl provides command line access to almost all the features defined in the
 EWMH specification. For example it can maximize windows, make them sticky, set
 them to be always on top. It can switch and resize desktops and perform many
 other useful operations.

For instance, on my currently running desktop:

oin$ wmctrl -l
0x00c00003 -1 oin Top Panel
0x00c0002d -1 oin Bottom Panel
0x00e00021 -1 oin Desktop
0x0280001f  0 oin root@gto: ~
0x02800f75  1 oin root@lemans: ~
0x02802735  2 oin Terminal
0x02600023  3 oin Holly Cole - I Will Wait for You
0x02a00020  2 oin linux icccm raise command - Google Search
0x028048a9  0 oin root@oin: ~

To switch my current screen to RhythmBox, and raise it to foreground:

oin$ wmctrl -a "Holly Cole - I Will Wait for You"
[div align=\"right\"][a href=\"index.php?act=findpost&pid=156439\"][{POST_SNAPBACK}][/a][/div]

now you tell me after i spend hours reading the X and wnck api
SL-C3000 - pdaXii13 build5.4.9 (based on pdaXrom beta3) / SL-C3100 - Sharp ROM 1.02 JP (heavily customised)
Netgear MA701 CF, SanDisk ConnectPlus CF, Socket Bluetooth CF, 4GB Kingston CF,  4GB pqi SD, 4GB ChoiceOnly SD, 2GB SanDisk SD USB Plus, 1GB SanDisk USB Plus, 1GB Transcend SD, 2GB SanDisk MicroSD with SD adaptor, Piel Frama Leather Case, GoldX 5-in-1 USB cable, USB hub, USB mouse, USB keyboard, USB ethernet, USB HDD, many other USB accessories...
(Zaurus SL-C3000 owner since March 14. 2005, Zaurus SL-C3100 owner since September 21. 2005)
http://members.iinet.net.au/~wyso/myZaurus - zBook3K

Drake01

  • Full Member
  • ***
  • Posts: 226
    • View Profile
Is There A Command Line Utility
« Reply #14 on: March 15, 2007, 08:29:27 pm »
Quote
I think what you're looking for is wmctrl:[div align=\"right\"][a href=\"index.php?act=findpost&pid=156439\"][{POST_SNAPBACK}][/a][/div]
I don't seem to have that command on either my Zaurus or my desktop.  Is this supposed to be a "stock" command?
Device: SL-C3200 running pdaXii13v2 build 5.5.0
Networking: Symbol Spectrum24 WLAN card; Kingston CIO10T CF NIC
Storage: 4GB Transcend 150x SD; 16GB Transcend 133x CF; 4GB Seagate CF HDD; 4GB Patriot SD
HID: Logitech V450 Laser Mouse; generic silicone USB keyboard; 2 generic optical mice; stock plastic stylus
GPS: generic "UT-41" USB GPS Receiver
Case: neoprene case from my old Palm foldable keyboard