![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
Hello, Unregistered You are browsing a READ only archive of the main support categories pre 4/21/2008. You will not be able to post or reply any threads in this section.
|
|
Absolute Beginner Talk The perfect starting place to find out more about computers, Linux and Ubuntu. |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Quad Shot of Ubuntu
![]() Join Date: Sep 2006
Location: Spain
Beans: 404
Kubuntu 7.04 Feisty Fawn
|
[SOLVED] Start aMule (or any program) when screensaver starts???
Ok...I would like to know if there's a way to start aMule (or Amarok...etc.) when the screensaver starts...I can't use cron(can I??)...and I can't find any info here...so posting a thread is my only option!!!
|
|
|
|
|
|
#2 |
|
Quad Shot of Ubuntu
![]() Join Date: Sep 2006
Location: Spain
Beans: 404
Kubuntu 7.04 Feisty Fawn
|
Re: Start aMule (or any program) when screensaver starts???
Anyone???
|
|
|
|
|
|
#3 |
|
5 Cups of Ubuntu
![]() Join Date: Jun 2007
Beans: 31
Ubuntu 7.04 Feisty Fawn
|
Re: Start aMule (or any program) when screensaver starts???
It's a bit quick and dirty, but paste the following into a file and save it as something like /home/sad_iq/bin/screenwatch.py.
Code:
#!/usr/bin/python
import os
import time
RUNME = "aMule"
ARGS = ""
screensaver_started = 0
running = 0
while 1:
active = 0
out = ""
pid = 0
if screensaver_started == 0:
# Don't do anything if the screensaver isn't running
s = os.popen("pidof gnome-screensaver")
spid = s.read()
s.close()
if len(spid) > 0:
screensaver_started = 1
else:
h = os.popen("gnome-screensaver-command -q", "r")
out = h.read()
active = out.find("inactive")
h.close()
if active < 0 and running == 0:
os.system("%s %s &" % (RUNME, ARGS))
running = 1
elif active > 0 and running == 1:
os.system("pkill %s" % RUNME)
running = 0
time.sleep(5)
Edit the values RUNME to reflect the command you want to run and ARGS for any arguments you want to pass the command. eg if you want to run Code:
xmms foobar.mp3 Code:
RUNME = "xmms" ARGS = "foobar.mp3" Make the script executable: Code:
chmod 750 /home/sad_iq/bin/screenwatch.py Code:
/home/sad_iq/bin/screenwatch.py gnome-screensaver-command -a Now set the script to run when you log in by adding it to your startup session via System -> Preferences -> Sessions. Enjoy.
__________________
Mike Peters http://www.ice2o.com Gates' Law: Every 18 months, the speed of software halves. |
|
|
|
|
|
#4 |
|
Quad Shot of Ubuntu
![]() Join Date: Sep 2006
Location: Spain
Beans: 404
Kubuntu 7.04 Feisty Fawn
|
Re: Start aMule (or any program) when screensaver starts???
Hey...Finally ...someone answered...Thanks...only a little problem...I use Kubuntu...so I think that gnome-screensaver isn't available (don't know if installing it will make it the default screensaver app in kubuntu)...so..all I have to do is find the replacement...and to test your script
|
|
|
|
|
|
#5 | |
|
5 Cups of Ubuntu
![]() Join Date: Jun 2007
Beans: 31
Ubuntu 7.04 Feisty Fawn
|
Re: Start aMule (or any program) when screensaver starts???
Quote:
Whilst checking to see if I could find what KDE uses I discovered you can do this very easily with xscreensaver if you're using that, or are willing to switch. The man page even provides an example Perl script. From the xscreensaver-command man page: Code:
#!/usr/bin/perl
my $blanked = 0;
open (IN, "xscreensaver-command -watch |");
while (<IN>) {
if (m/^(BLANK|LOCK)/) {
if (!$blanked) {
system "sound-off";
$blanked = 1;
}
} elsif (m/^UNBLANK/) {
system "sound-on";
$blanked = 0;
}
}
Set the script up to run the same as I explained for mine.
__________________
Mike Peters http://www.ice2o.com Gates' Law: Every 18 months, the speed of software halves. |
|
|
|
|
|
|
#6 |
|
Quad Shot of Ubuntu
![]() Join Date: Sep 2006
Location: Spain
Beans: 404
Kubuntu 7.04 Feisty Fawn
|
Re: Start aMule (or any program) when screensaver starts???
Ok...Works great...better than I expected...(the xscreensaver that is)...and it doesn't have to be a blank screen...amule now starts when the screensaver activates
Code:
if (m/^(BLANK|LOCK)/) {
if (!$blanked) {
system "sound-off";
$blanked = 1;
}
Code:
if (m/^(BLANK|LOCK)/) {
if (!$blanked) {
system "amule";
$blanked = 1;
}
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|