4

The original question

Sound indicator

One of the strength of Unity are the various standardized indicators. I want to customize the sound indicator with an additional menu entry that runs a small shell script. I'm not afraid of a little Python code and I hope someone can point me to the right subroutine in the right file. I suspect that will be fairly easy but all the indicators are just so bloated that I can't look through their code in a reasonable time.

Any help is appreciated. I know it is possible as the marvelous Skype-Wrapper does it.


Edit 2 - Now a dirty DBus hack

The one click problem from one edit before has now turned into a DBus problem. Basically we have to tell the sound indicator that our bogus player has terminated now. A dirty hack navigates around that problem:

#!/bin/bash
# This is '/home/confus/bin/toggleSpeaker.sh'

notify-send "Toggle Speaker" "$(date)"
qdbus \
    com.canonical.indicator.sound  \
    /org/ayatana/indicator/service \
    org.ayatana.indicator.service.Shutdown
exit 0

Help from the community is appreciated as I don't have experience any with DBus whatsoever.


Edit 1 - Takkat found a solution but only clickable once?

For some reason the solution proposed by Takkat has the drawback that the resulting entry in indicator sound can only be clicked once per session. If someone has a fix for, than please comment or answer, you will be upvoted. Here you can see the result:

Sound indicator with script entry

I strongly suspect the issue is related to the .desktop-file in /home/confus/.local/share/application/toggleSpeaker.desktop, which is this:

[Desktop Entry]
Type=Application

Name=toggleSpeaker
GenericName=Toggle Speaker

Icon=gstreamer-properties

Exec=/home/confus/bin/toggleSpeaker.sh
Terminal=false

And here is a minimal example of the script in /home/confus/bin/toggleSpeaker.sh for your consideration:

#!/bin/bash
# This is '/home/confus/bin/toggleSpeaker.sh'

notify-send "Toggle Speaker" "$(date)"
exit 0
1
  • 1
    Boy this really turns into a real pain in the rear. There is a lack of documentation and help resources. Also it seems that Unity has made customizations of this sort unnecessary complicated.
    – con-f-use
    Aug 29, 2012 at 20:16

1 Answer 1

4

By running dconf-editor from the dconf-tools Install dconf-tools we may incorporate an MPRIS complatible media player application to the sound menu with the key "com.canonical.indicator.sound.interested-media-players".

enter image description here

In the example here test was included which points to a test.desktop file in ~/.local/share/applications where we can run our appplication from the Exec= field. Restart your session to take effect.

enter image description here

As an entry in this menu is closely related to a media player, application control is done by DBus session bus com.canonical.indicator.sound. This is why we will not be able to re-run a script until a reset of the indicator was done. I succeeded to restart the test application after performing Shutdown() on the org/ayatana/indicator/service object but this is quite a hack and definitely not the way the indicator sound menu should be used.

It may however point to the right direction. i.e. we need to make use of DBus for our script or application we want to reside in the sound indicator menu.

5
  • To get an icon the launcher must have the Icon= property set. Next small question: For me the script is run exactly one time in each session. Further clicks on the entry are just ignored. Do you have an idea why this is?
    – con-f-use
    Aug 29, 2012 at 8:34
  • Well I adapted the stock .desktop file from audacious witch said Icon=audacious and that displayed Audacious' icon in my custom indicator entry. The run once issue might be connected to my adapting the audacious launcher. Could you post the code of your .desktop? I posted mine.
    – con-f-use
    Aug 29, 2012 at 9:14
  • Thanks a lot. Can you post your code? I've never worked with DBus before.
    – con-f-use
    Aug 29, 2012 at 19:49
  • Nevermind, this did it for me from within a terminal: qdbus com.canonical.indicator.sound /org/ayatana/indicator/service org.ayatana.indicator.service.Shutdown. Though I've no idea what I'm doing. Are you working on an orthodox solution? If so could you please explain it in simple terms while you're at it. Your help was very appreciated! Thanks a lot!
    – con-f-use
    Aug 29, 2012 at 20:01
  • 1
    Same here - I've no idea what else we might shutdown by this. A better solution would be to write an application/script that is controlled by DBus - I guess this is a lot more work.
    – Takkat
    Aug 29, 2012 at 20:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .