You are not logged in.
Hi guys,
What do you think about the idea to run custom code depending on the AC state?
For example start /usr/bin/dropboxd if laptop is charging. If laptop is running on battery, run /usr/bin/killall dropboxd.
Would you find that a useful addition to Xfce Power Manager?
Thanks for your answers!
Last edited by sonycdr (2014-10-11 14:17:49)
Offline
That would definitely be a good idea - especially for user-based scripts.
As a workaround, if you are using a distro that uses pm-utils, you can tie this into the power management sub-system. Create a file in your /etc/pm/power.d directory with the following content:
#!/bin/bash
USERNAME=userid
case $1 in
true) #on_battery
/usr/bin/killall dropboxd
;;
false) #on_ac
export DISPLAY=":0"
export XAUTHORITY="/home/$USERNAME/.Xauthority"
su $USERNAME -c "/usr/bin/dropboxd"
;;
*) exit 1 ;;
esac
exit 0
...change the "USERNAME=userid" to specify your username and make the file executable. On every change of power status (on_battery vs on_ac), this script will be run and it should stop and start dropbox.
This is also possible if you are using a distro that uses systemd, but I don't know the commands off of the top of my head.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
@ToZ
Thanks a lot for your comment! I am glad that you find the idea useful.
I created the directory and the script above but I am not sure if it will work.
I am using Arch Linux and systemd. I tried to install pm-utils but it conflicts with TLP that I am heavily using:
:: pm-utils and tlp are in conflict. Remove tlp? [y/N]
This is also possible if you are using a distro that uses systemd, but I don't know the commands off of the top of my head.
It would be great to know how to do that with systemd!
Offline
Then lets just use udev.
1. Create the file /usr/local/bin/dropbox_power as above with the following content:
#!/bin/bash
USERNAME=userid
case $1 in
true) #on_battery
/usr/bin/killall dropbox
;;
false) #on_ac
export DISPLAY=":0"
export XAUTHORITY="/home/$USERNAME/.Xauthority"
su $USERNAME -c "/usr/bin/dropboxd"
;;
*) exit 1 ;;
esac
exit 0
...and make the file executable. Make sure to change the "USERNAME=userid" to suit. Also note, that on my system, the dropbox executable that is running is called just dropbox (not dropboxd). I've made that change to this script.
2. Create the udev rule as /etc/udev/rules.d/98-dropbox.rules with the following content:
SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/usr/local/bin/dropbox_power true"
SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/usr/local/bin/dropbox_power false"
...and reload the rules:
sudo udevadm control --reload-rules
3. Test it out.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
I was thinking about a Udev solution before but it is not the recommended way to do:
https://bugs.launchpad.net/ubuntu/+sour … ug/1297248
Basically udev should only be used for short calls (max 30s) but not to run full scripts.
Offline
This script shouldn't take more than a couple of seconds to run - won't be anywhere near 30 seconds. And since udev already recognizes the plug/unplug action, it makes sense to me to tie it in there.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
I will try it out, thanks!
Concerning adding a custom code feature to power manager, how should I proceed?
Are the developers are my request already or should I post it on the bugtracker?
Offline
Are the developers are my request already or should I post it on the bugtracker?
It would be best to post a request on the bug tracker.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Created a new bug report. Curious to see the comments from the developers.
Offline
[ Generated in 0.008 seconds, 7 queries executed - Memory usage: 556.84 KiB (Peak: 573.68 KiB) ]