View Poll Results: Do you think NetworkManager should include custom sound alerts?

Voters
2. You may not vote on this poll
  • YES

    2 100.00%
  • NO

    0 0%
Results 1 to 4 of 4

Thread: NetworkManager Sound Notifications

Hybrid View

  1. #1
    Join Date
    May 2010
    Beans
    12
    Distro
    Ubuntu 16.04 Xenial Xerus

    Lightbulb NetworkManager Sound Notifications

    I think it would be quite nice if we could configure NetworkManager to play a custom audible notification (wav file) upon establishing Internet connection and upon disconnecting from the Internet as well. Is there any workaround for this feature yet?

    Last edited by madjoe; May 23rd, 2010 at 11:39 AM.

  2. #2
    Join Date
    May 2010
    Beans
    12
    Distro
    Ubuntu 16.04 Xenial Xerus

    Arrow [solved]

    For those who would like to enable this feature, here's a workaround:

    • http://bpaste.net/show/9289/ -- save that as /etc/NetworkManager/dispatcher.d/99playsound and chmod +x it.
    • Edit the last 4 lines to tell it what to do.


    Usecase:
    If you are dealing with poor WiFi connection, downloading something and if you're afk, probably you'd like to know when your Internet connection goes offline (if you're close enough to hear a sound notification, of course).

    Thanks to Seveas @ #ubuntu! =D>


    99playsound:
    Code:
    #!/usr/bin/python
    
    import os
    import stat
    import sys
    import subprocess
    
    # This is run as root, but mplayer should run as the user. Find the
    # proc folder of nm-applet and copy its environment. Also setuid to the
    # correct user so gnome-keyring accepts the connection
    for d in os.listdir('/proc'):
        if not d.isdigit():
            continue
        d = os.path.join('/proc', d)
        try:
            exe = os.readlink(os.path.join(d, 'exe'))
        except OSError:
            continue
        if exe == '/usr/bin/nm-applet':
            uid = os.stat(d)[stat.ST_UID]
            env = open(os.path.join(d, 'environ')).read()
            env = dict([x.split('=', 1) for x in env.split('\x00') if x])
            os.environ.update(env)
            os.setuid(uid)
            break
    else:
        # Can't find nm-applet
        sys.exit(0)
    
    # This is called from n-m as <script> <device> <action>
    if sys.argv[2] != 'up':
        subprocess.call(['/usr/bin/paplay','/home/madjoe/down.wav'])
    else:
        subprocess.call(['/usr/bin/paplay','/home/madjoe/up.wav'])
    Last edited by madjoe; September 5th, 2010 at 12:08 AM.

  3. #3
    Join Date
    Jan 2011
    Location
    Chhattisgarh, India.
    Beans
    9

    Re: NetworkManager Sound Notifications

    will it work for mobile broadband . I pasted sound files in home folder and 99playsound in place but it is not working. I also didnt understand "chmod+x"
    PLEASE HELP I NEED THIS.

  4. #4
    Join Date
    Nov 2007
    Location
    .mx
    Beans
    305
    Distro
    Ubuntu

    Re: [solved]

    Quote Originally Posted by madjoe View Post
    Code:
    ...
    if sys.argv[2] != 'up':
        subprocess.call(['/usr/bin/paplay','/home/madjoe/down.wav'])
    else:
        subprocess.call(['/usr/bin/paplay','/home/madjoe/up.wav'])
    Did you replace '/home/madjoe/down.wav' and '/home/madjoe/up.wav' with your own files?

    Did you save the script as /etc/NetworkManager/dispatcher.d/99playsound ?

    If so, in terminal:
    sudo chmod +x /etc/NetworkManager/dispatcher.d/99playsound

    This sets it as an executable file, which allows it to run as a script.

    https://help.ubuntu.com/community/FilePermissions for more info
    Shamelessly plugging my GLog! (GeekLog) in every post I can
    If your problem is solved, please do take the time to mention it and Mark the Thread as Solved!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •