Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question is in the context of Lucid 10.04 desktop (ie. no Unity).

I do most screen navigation via the keyboard (not the mouse), so I'm looking for a script solution to re-activating an app which has been "minimized" to the Panel's Notification Area.

I'll use Skype as an example.

wmctrl allows me enough access to normally-minimized windows, but when Skype is "minimized" to the Notification Area, it simply goes "off the radar" as far as wmctrl is concerned.

Bearing in mind that icon positions in the Notification Area can vary, is there some way to determine the screen co-ordinates of Skype's Panel icon, so I can "click" it using xdotool (or a similar utility)?

...or maybe there is a more direct way to activate the "dormant" Skype? ... (and I don't mean the mouse ;)

Here is the script, so far. Hopefully it will make clear what I'm trying to do:

#!/bin/bash
procname="skype-wrapper"
windmask="Skype™"
if [[ $(pgrep -x -n -c "$procname") == 1 ]] ; then 
  wintitle="$(wmctrl -l |grep "$windmask" |head -n 1 |sed -n "s/^.\+${HOSTNAME} \(.*\)/\1/p")"
  if [ "$wintitle" = "" ] ; then
    echo "Click on Skype's Panel-icon to show the main window"  
    ###############################################################
    # How can I find the screen co-ordinates of Skype's Panel Icon
    ###############################################################
  else
    # Skype is running, and has (at least) one visible window which matches $windmask. Activate it.
   wmctrl -a "$wintitle"
  fi
else 
  # The process is not currently running. Start it.
  ("$procname" &)
fi
share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

http://d01.megashares.com/dl/161a012/Skype.zip

  • zskypewrapper.sh is my custom script to show Skype (@fred.bear, for right or wrong, I just 'wmctrl -a Skype™' to show an already-existing window).
  • showskype.py is ændrük's script above, modified to also print Skype's return code.
  • Skype.desktop is a .desktop file I created for use with Docky, which is the whole reason I wrote zskypewrapper.sh (but zskypewrapper will work without the .desktop, and I even threw in some logic which is only useful from the command-line and Docky never can use). This .desktop is not needed, per se; all I did was nautilus->right-click->create launcher and put in zskypewrapper.sh.

zskypewrapper.sh and showskype.py need to be executable and in $PATH somewhere.

Hope this helps someone. :-D

share|improve this answer
    
Thanks zpletan (and of course, ændrük)... This is definitely the best way for Skype... The method I described (in my answer) works well enough for 'not directly' controlable panel icons, but it has associated constraints, like: Changing the Panel's colour scheme requires resetting it, and it doesn't work when a full screen app hides the panel, and Skype was a pain to set up, because of all the different status icons it uses... Now, with your Skype solution, its all fair weather sailing ! –  Peter.O Jan 12 '11 at 3:52
add comment

How about:

#!/usr/bin/env python

import dbus

# Get a D-Bus interface to Skype
bus = dbus.SessionBus()
skype_object = bus.get_object('com.Skype.API', '/com/Skype')
skype = dbus.Interface(skype_object, dbus_interface='com.Skype.API')

# Ask for permission to control Skype
response = skype.Invoke("NAME " + __file__)
response = skype.Invoke("PROTOCOL 8")

# Issue commands
response = skype.Invoke("SET WINDOWSTATE NORMAL")

It's not as generalized as you wanted, but it might get the job done. For anything other than simple personal use it will need some error handling added in.

Source: Skype Public API Reference

share|improve this answer
    
ændrük. It seems a good method forSkype, but I'm afraid it is a bit beyond me. I have minimal bash and python knowledge, so when it failed on "skype_object = ...", and my skype --help does not list the "--enable-dbus --use-system-dbus" options, and I see things in the "public_api_ref" like "Important: The Skype for Linux API, version 1.3, beta uses D-BUS version .23. The next release will move to support for D-BUS version .61+". Ubuntu's dbus version is 1.2.16-2. It seems that the best thing I can do is have a cup of coffee... Thanks. (I might scan for unique pixel groups; easier :) –  Peter.O Dec 8 '10 at 8:51
    
Yikes, looks like old documentation. --enable-dbus --use-system-dbus shouldn't be necessary, and apparently this only works after you have signed in to Skype. –  ændrük Dec 8 '10 at 15:06
add comment

I've managed to put together a python script which does the job (... a big learning curve, and a good way to learn :)

It won't make it to mainstream, but I'm posting it for anyone who may be interested.

Because there is no way I know of to directly determine the co-ordinates of a particular Notification-Tray icon, I've had to "search" for the icon.

To identify an icon, the script has a "one time per icon" CAPTURE proc, which identifies a (hopefully) unique row of pixels... fortunately icons are very multi-coloured.
(the capture proc calls on 2 minor bash scripts)

I'm not sure what the askubuntu policy is regarding a large code posting, so until I find out if it is Okay or not, I've posted it to pastebin.ubuntu.com

The main script is 140 lines of actual code, but runs to 240 with coments, and for some unknown reason, when in the pastebin, many but not all of the lines are double-spaced, pushing it to 339! (my editor is set to Unix LF)...

Here are the links to the main python scripts and the 2 helper bash scripts;

share|improve this answer
    
I'm getting more impressed by your ability to learn things every day. Fantastic stuff, keep it coming! –  Stefano Palazzo Dec 10 '10 at 1:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.