LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Recurring startup application (https://www.linuxquestions.org/questions/linux-newbie-8/recurring-startup-application-4175532611/)

zetrotrack000 01-31-2015 10:56 AM

Recurring startup application
 
Hi
Kindly refer to following post:
http://www.linuxforums.org/forum/pro...tml#post954718
Here, at post #4, solution given by "LSalab" worked for me. So I added it to startup applications in my cinnamon desktop. But the problem is that, it works only once after every login (when the battery gets lower than 10% so it informs me), and if I charge the battery and again it reaches that threshold point of 10%, the system does not inform me, which means that the startup script only executes once.
here is the script:
Code:

#!/bin/bash
while [[ `acpi | cut -d ' ' -f 4 | grep -Po '\d+'` -gt 10 ]]
do echo -ne "\r`acpi`"
sleep 5
done
notify-send -t 60000 'Low Battery' 'Battery charging of your system is below 10%. Kindly Plug charger. Thanks.'
echo ''
mplayer /usr/share/sounds/freedesktop/stereo/phone-outgoing-busy.oga -loop 0

So my question is that, how can I make this script recurring at every threshold level?
Regards

unSpawn 02-01-2015 07:29 AM

Use "less or equal to"? Plus I think this is slightly cleaner because you don't actually need the command line 'acpi' tool to read the battery state:
Code:

#!/bin/bash --
BATT_STATE="/sys/class/power_supply/BAT0/capacity"; [ -e $BATT_STATE ] \
&& { [ $(cat $BATT_STATE) -le 10 ] && notify-send -t 60000 "Battery status" "Battery below or at 10%."; } || \
 { notify-send -t 60000 "Battery status" "Cant find $BATT_STATE."; exit 1; }
exit 0


zetrotrack000 02-01-2015 08:35 AM

Thanks. However the original question still stands that: how to make it recurring? :)

ssokolow 02-01-2015 07:41 PM

I decided to help zerotrack000 out and got carried away.
Basically, I wrote a little battery warning application in Python so it could properly interact with things like UPower and the notification daemon to get the best results.

zetrotrack000 02-02-2015 03:30 PM

Yes, its working perfectly, thanks ssokolow :)

However, I was experimenting with it and tried to add it in startup by using following file:
Code:

~/.config/autostart/batterymonitor.desktop
with these settings:
Code:

[Desktop Entry]
Type=Application
Exec=python /home/<myusername>/scripts/battery_monitor.py
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_US]=batterymonitor
Name=batterymonitor
Comment[en_US]=Python Battery Monitor
Comment=Python Battery Monitor
X-GNOME-Autostart-Delay=0

But it seems here that the script is not loading at desktop login. Am I doing wrong something here or what?
Regards

ssokolow 02-03-2015 04:01 AM

That looks OK as long as you've confirmed that running "python /home/<myusername>/scripts/battery_monitor.py" in the terminal works.

I'd have used "chmod +x battery_monitor.py" and "Exec=/home/<myusername>/scripts/battery_monitor.py" but, as long as you're on a distro where "python" aliases to "python2" and not "python3", they should be equivalent. (It should work under Python 3, but the instructions I gave you installed the Python 2.x versions of notify2 and PyGI.)

We need to narrow down the problem so try launching it by running "xdg-open ~/.config/autostart/batterymonitor.desktop" and tell me if it works.

zetrotrack000 02-03-2015 07:11 AM

ssokolow!
I think I have found the problem. I have messed up the battery_monitor.py file, so I downloaded it again and its seems to be loaded at startup. I am still checking and experimenting. I will confirm in few hours. If I want to chat, please PM me that where I can find you?
Regards

zetrotrack000 02-03-2015 11:17 AM

Its still not loading at startup :(
Here is the ~.config/autostart/batterymonitor.desktop file:
Code:

[Desktop Entry]
Type=Application
Exec=python /home/<myusername>/scripts/battery_monitor.py
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_US]=BatteryMonitor
Name=BatteryMonitor
Comment[en_US]=
Comment=
X-GNOME-Autostart-Delay=0

The file is also executable and working fine from terminal. I don't know
what may be wrong here!

zetrotrack000 02-03-2015 12:51 PM

One more thing. I felt that keeping that python script running in the background causes the battery to drain a bit faster. What do you think?

ssokolow 02-04-2015 07:02 AM

Quote:

If I want to chat, please PM me that where I can find you?
If you want something more immediate than the mail form on my blog, I'm persistently connected to FreeNode under the nick you talked to me at. (Though, if that nick was ghosted when I got disconnected and reconnected, you'll have to replace the last character with the number 1)

Quote:

One more thing. I felt that keeping that python script running in the background causes the battery to drain a bit faster. What do you think?
It's possible that there's something I didn't take into account since I have no laptop to test on locally. Install PowerTOP and see if the script shows up under Overview as a significant source of wakeups. (Also, check the Tunables tab for a bunch of things you can do to improve your battery life.)


All times are GMT -5. The time now is 06:04 PM.