LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-31-2015, 11:56 AM   #1
zetrotrack000
Member
 
Registered: Dec 2011
Posts: 223

Rep: Reputation: Disabled
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
 
Old 02-01-2015, 08:29 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
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
 
Old 02-01-2015, 09:35 AM   #3
zetrotrack000
Member
 
Registered: Dec 2011
Posts: 223

Original Poster
Rep: Reputation: Disabled
Thanks. However the original question still stands that: how to make it recurring?
 
Old 02-01-2015, 08:41 PM   #4
ssokolow
LQ Newbie
 
Registered: Aug 2004
Location: Canada
Posts: 27

Rep: Reputation: 16
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.
 
Old 02-02-2015, 04:30 PM   #5
zetrotrack000
Member
 
Registered: Dec 2011
Posts: 223

Original Poster
Rep: Reputation: Disabled
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
 
Old 02-03-2015, 05:01 AM   #6
ssokolow
LQ Newbie
 
Registered: Aug 2004
Location: Canada
Posts: 27

Rep: Reputation: 16
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.
 
Old 02-03-2015, 08:11 AM   #7
zetrotrack000
Member
 
Registered: Dec 2011
Posts: 223

Original Poster
Rep: Reputation: Disabled
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
 
Old 02-03-2015, 12:17 PM   #8
zetrotrack000
Member
 
Registered: Dec 2011
Posts: 223

Original Poster
Rep: Reputation: Disabled
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!
 
Old 02-03-2015, 01:51 PM   #9
zetrotrack000
Member
 
Registered: Dec 2011
Posts: 223

Original Poster
Rep: Reputation: Disabled
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?
 
Old 02-04-2015, 08:02 AM   #10
ssokolow
LQ Newbie
 
Registered: Aug 2004
Location: Canada
Posts: 27

Rep: Reputation: 16
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.)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Where do Startup Application go? sorvad Red Hat 2 11-12-2014 03:15 AM
[SOLVED] how to launch different application on startup julybrownie Linux - Newbie 2 08-15-2012 01:10 PM
run application in startup naveenisback Programming 4 01-19-2010 09:25 AM
application firing at startup ekdya Fedora 1 10-03-2006 02:24 AM
application startup problem tuxrules Linux - Newbie 10 10-10-2004 02:19 AM


All times are GMT -5. The time now is 07:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration