Find the answer to your Linux question:
Results 1 to 7 of 7
Hi I want to create 2 alerts which can produce a DING like sound (like when transmission client produces when torrent download completes) for me. One when battery charging reached ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2012
    Posts
    18

    Create sound alerts for battery charging


    Hi
    I want to create 2 alerts which can produce a DING like sound (like when transmission client produces when torrent download completes) for me. One when battery charging reached 20% and other when battery charging reached 80%. How can I do this?
    PS. I'm not sure but I think that this is the right place to post the problem, as this may require to create a bash script.
    Regards

  2. #2
    Just Joined!
    Join Date
    Mar 2007
    Location
    Bogotá, Colombia
    Posts
    46
    For the alerts themselves, I would take a look at the man page for 'aplay'. You can play a sound file with that (something like ding.wav).

    If you want to monitor the battery charge, then take a look at the acpi command. I once built a small one-liner to send a notification via zenity if my battery got below 15%.

    And yes, you can build a small bash script for that.

  3. #3
    Just Joined!
    Join Date
    Feb 2012
    Posts
    18
    Quote Originally Posted by LSalab View Post
    I once built a small one-liner to send a notification via zenity if my battery got below 15%.
    Can you share that one-liner with me?
    Regards

  4. #4
    Just Joined!
    Join Date
    Mar 2007
    Location
    Bogotá, Colombia
    Posts
    46
    Sure, this is what I did some time ago:

    Code:
    while [[ `acpi | cut -d ' ' -f 4 | grep -Po '\d+'` -gt 15 ]] ; do echo -ne "\r`acpi`" ; sleep 5 ; done ; notify-send -t 60000 'low batt' 'low batt' ; echo ''
    Also, I apologize for the confusion. I used 'notify-send' not 'zenity', it slipped my mind on the previous post. But the concept applies.

  5. #5
    Just Joined!
    Join Date
    Feb 2012
    Posts
    18
    Thanks a lot

  6. #6
    Just Joined!
    Join Date
    Feb 2012
    Posts
    18
    Quote Originally Posted by LSalab View Post
    Sure, this is what I did some time ago:

    Code:
    while [[ `acpi | cut -d ' ' -f 4 | grep -Po '\d+'` -gt 15 ]] ; do echo -ne "\r`acpi`" ; sleep 5 ; done ; notify-send -t 60000 'low batt' 'low batt' ; echo ''
    Also, I apologize for the confusion. I used 'notify-send' not 'zenity', it slipped my mind on the previous post. But the concept applies.
    That solved one issue i.e low battery, leaving one issue i.e notification when battery charged to 80% while charging. How can I do this?
    Regards

  7. #7
    Just Joined!
    Join Date
    Mar 2007
    Location
    Bogotá, Colombia
    Posts
    46
    Within the while loop, you can place a conditional construct to evaluate the 80% batt.

    Take a look a this:

    Bash Reference Manual - Conditional Constructs

Posting Permissions

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