Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[KDE] Bind scripts to the screensaver start/stop
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
marco.difresco
Tux's lil' helper
Tux's lil' helper


Joined: 29 Jul 2011
Posts: 102

PostPosted: Sat Jan 18, 2014 10:30 am    Post subject: [KDE] Bind scripts to the screensaver start/stop Reply with quote

Hi all,
I have tried to search around, but without success.

Is it possible to configure KDE to launch specific scripts when the screensaver start and stop (one script on start and one on stop)?

I am doing some bitcoin mining and I am trying to balance the uptime of the mining program and not having the PC locked up by it when I am at my desk. So far I relied on crontab, but since I have to input the exact times for it to work, I have to input the average times I leave for lunch/dinner and when I go to bed in the evening and the average time I am back to stop the program, but this solution means that if I leave later and/or I return earlier than these average times I have to deal with the lagginess of the desktop until crontab reach the time to call the stopping script and, on the other end, if I leave earlier and/or return later I have some wasted computer time where the mining program isn't running.

Thank you in advance.
_________________
Marco Di Fresco
Silicon Gadget
Import MSSQL bak files to MySQL
Back to top
View user's profile Send private message
franzf
Advocate
Advocate


Joined: 29 Mar 2005
Posts: 4403

PostPosted: Sat Jan 18, 2014 11:28 am    Post subject: Reply with quote

Why not just use nice/ionice to set priority of your bitcoin script so that it does not disturb you when you are working?
Back to top
View user's profile Send private message
aCOSwt
Bodhisattva
Bodhisattva


Joined: 19 Oct 2007
Posts: 2537
Location: Hilbert space

PostPosted: Sat Jan 18, 2014 1:25 pm    Post subject: Reply with quote

Be aware that I do not precisely know waht I am talking about since I don't make use of screensavers.

1/ It seems that kde screensaver can be easily replaced by the XScreenSaver.
In which case, browse : http://www.jwz.org/xscreensaver/man3.html
and scroll down to the description of the-watch option.

2/ I understand that the org.kde.screensaver service is provided by KRunner wich registers on dBus.
So, it must be possible to get access via dbus in some way.
Then... don't ask me where to find the appropriate documentation for the API. I... dont' know. :)
_________________
Back to top
View user's profile Send private message
marco.difresco
Tux's lil' helper
Tux's lil' helper


Joined: 29 Jul 2011
Posts: 102

PostPosted: Sat Jan 18, 2014 4:08 pm    Post subject: Reply with quote

Thank you both for your answers.

Following aCOSwt's answer as lead I ended up to the following two pages:
http://superuser.com/questions/205334/how-do-you-get-ubuntu-to-automatically-run-a-program-every-time-the-screen-is-un
http://www.linuxquestions.org/questions/fedora-35/start-and-stop-script-with-screensaver-728498/
that lead me to create the following script:
Code:
#!/bin/bash
dbus-monitor --session "type='signal',interface='org.freedesktop.ScreenSaver',member='ActiveChanged'" | while read line ; do
if [ x"$(echo "$line" | grep 'boolean true')" != x ] ; then
        ~/miner-start
fi
if [ x"$(echo "$line" | grep 'boolean false')" != x ] ; then
        ~/miner-stop
fi
done


~/miner-start and ~/miner-stop are two script that I was using with crontab and contain respectively:
Code:
killall cgminer
sleep 2
cgminer -c ~/.cgminer/cgminer.conf &


and

Code:
killall cgminer


(~/miner-start starts with a "killall cgminer" as a backup in case I accidentally start it twice).


The above script has one problem that prevent it from fully working: if I launch it from a console it will keep the console occupied (until I press CTRL+C), but it works when the screensaver start and stop; if I launch it with an & at the end (to get back the console and close it) or if I launch it at the user login (by link it to ~/.kde4/Autostart), it shows up on the task manager but it wouldn't work (nothing start/stop at the screensaver start/stop).

Any idea?

Thank you again for your help.
_________________
Marco Di Fresco
Silicon Gadget
Import MSSQL bak files to MySQL
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum