LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Fedora (https://www.linuxquestions.org/questions/fedora-35/)
-   -   Start and stop script with screensaver (https://www.linuxquestions.org/questions/fedora-35/start-and-stop-script-with-screensaver-728498/)

esoukenka 05-26-2009 12:19 AM

Start and stop script with screensaver
 
Hello I would like to start and stop rtorrent based on my screensaver. I used to do this awhile ago with ubuntu and still have my script which may be helpful to someone else.

However now I am using Fedora with KDE and the script no longer seems to work. Could someone please help me with either another solutions or assist me in getting this to work:

#!/usr/bin/perl
#gnome
my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver',member='SessionIdleChanged'\"";

open (IN, "$cmd |");

while (<IN>) {
if (m/^\s+boolean true/) {
#when screensaver activates, run the following commands
#system("/home/eric/compiled/scripts/rtorrentstart");
system("touch /home/asoukenka/rtorrenthasstarted");
} elsif (m/^\s+boolean false/) {
#when screensaver deactivates, run the following commands
#system("kill `pgrep rtorrent`");
system("touch /home/asoukenka/rtorrenthasbeenkilled");
}
}


just found my old post where some people helped me with this
http://ubuntuforums.org/archive/index.php/t-977249.html

fpmurphy 05-26-2009 08:38 AM

For starters, the interface name needs to be changed since you are no longer using GNOME. Something like "org.kde.Screensaver"
Quote:

my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver',member='SessionIdleChanged'\"";
Use qdbus or qdbusviewer to figure out the exact object and method names.

esoukenka 05-26-2009 12:55 PM

Thank you require further assistance though
 
Nevermind all is fixed now. For those who want it here is the final script.

#!/usr/bin/perl
#requires:
# rtorrent, screen, gnome/kde, perl
#
# Instructions:
# - Properly comment the line for gnome or kde
# - Give script execute permission (chmod +x)
# - Run script ./<scriptname> **** do not use rtorrent in script name will mess up kill command
#
# There is a log file created by the script at /tmp/autortorrent
#
#


#gnome
#my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver',member='SessionIdleChanged'\"";

#kde
my $cmd = "dbus-monitor --session \"type='signal',interface='org.freedesktop.ScreenSaver',member='ActiveChanged'\"";
open (IN, "$cmd |");

while (<IN>) {
if (m/^\s+boolean true/) {
#when screensaver activates, run the following commands
system("echo \"--------------------------------------------------------------------\" >> /tmp/autortorrent");
system("screen -dmS rtorrent rtorrent");
system("echo \"started:\" >> /tmp/autortorrent");
system("date >> /tmp/autortorrent");
system("echo \"--------------------------------------------------------------------\" >> /tmp/autortorrent");
} elsif (m/^\s+boolean false/) {
#when screensaver deactivates, run the following commands
system("echo \"--------------------------------------------------------------------\" >> /tmp/autortorrent");
system("kill `pgrep rtorrent`");
system("echo \"stopped:\" >> /tmp/autortorrent");
system("date >> /tmp/autortorrent");
#system("ps aux |grep rtorrent >> /tmp/autortorrent");
system("echo \"--------------------------------------------------------------------\" >> /tmp/autortorrent");
}
}

karlacio 11-08-2011 06:04 AM

Hello,

I slightly modified your code to have Kopete disconnected on screen saver start and reconnect when screen saver unlock...



Code:

#!/usr/bin/perl


#gnome
#my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver',member='SessionIdleChanged'\"";

#kde
my $cmd = "dbus-monitor --session \"type='signal',interface='org.freedesktop.ScreenSaver',member='ActiveChanged'\"";
#my $cmd = "dbus-monitor --session \"type='signal'\"";
print "---$cmd----\n";
#exit;


open (IN, "$cmd |");

while (<IN>) {
  if (m/^\s+boolean true/) {
    #when screensaver activates, run the following commands
    system("dbus-send --type=method_call --dest=org.kde.kopete /Kopete org.kde.Kopete.disconnectAll");
    print "Kopete disconnected\n";
  } elsif (m/^\s+boolean false/) {
    #when screensaver deactivates, run the following commands
    system("dbus-send --type=method_call --dest=org.kde.kopete /Kopete org.kde.Kopete.connectAll");
    print "Kopete connected\n";
  }
}



All times are GMT -5. The time now is 05:54 PM.