Running screensaver and song at once

Forum rules
Before you post please read how to get help

Running screensaver and song at once

Postby Ertain on Tue Jan 17, 2012 5:21 pm

Hello everyone. This is my first time posting here, so I'm making it a good one.

I've been trying to writie a script (or at one time even reprogramming the application) which plays a song while a screensaver is running. I understand that GNOME 3 doesn't really have that much support for screensavers, but I like them so much as to not let them go.

At first I tried changing the command in the desktop file for the screensaver. I made it execute a script file with these lines:
Code: Select all
/usr/lib/xscreensaver/le_screensaver -root &
play /usr/share/sounds/le_music.ogg &


Sadly, that doesn't work. The song doesn't play at all. I'm sure it's because le_screensaver starts running, but it doesn't get around to playing le_music. I can't exactly figure out how the screensaver could start running and possibly wait a little for the music to start playing.

I have also tried using a script that's similar to the one I found in the FAQs section of the GNOME website.
Code: Select all
#!/usr/bin/perl -w

#gnome
my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver',member='ActiveChanged\"";
open (IN, "$cmd |") or die "Couldn't run dbus-monitor.\n";
print("dbus-monitor started.\n");

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

while (<IN>) {
if (m/^\s+boolean true/) {
  #when screensaver activates, run the following commands
  print("Playing song. \n");
  system("echo \"--------------------------------------------------------------------\" >> /tmp/play_sound.txt");
  system("echo \"started:\" >> /tmp/play_sound.txt");
  system("date >> /tmp/play_sound.txt");
  system("play \"/home/user/le_music.mp3\"");
   }
elsif (m/^\s+boolean false/) {
  system("echo \"--------------------------------------------------------------------\" >> /tmp/play_sound.txt");
  system("echo \"stopped:\" >> /tmp/play_sound.txt");
  system("date >> /tmp/play_sound.txt");
  system("echo \"--------------------------------------------------------------------\" >> /tmp/play_sound.txt");
  print("Stopping song. \n");
  system("kill `pgrep play`");
   }
}


What I do is run this script and, supposedly, it would start the music when the screensaver starts. This doesn't work, either, and I am not entirely certain why.

Might anyone else have an idea on this? If anyone's wondering about this I have the packages for xscreensaver installed (xscreensaver, xscreensaver-data, xscreensaver-data-extra, xscreensaver-gl, and xscreensaver-gl-extra).
Last edited by Ertain on Fri Jul 13, 2012 1:39 pm, edited 2 times in total.
Ertain
Level 1
Level 1
 
Posts: 14
Joined: Tue Jan 17, 2012 4:41 pm

Linux Mint is funded by ads and donations.
 

Re: Running screensaver and song at once

Postby xenopeek on Wed Jan 18, 2012 2:10 pm

What happens if you reverse the steps? Start playing the music first, and then pull up the screensaver?
User avatar
xenopeek
Level 21
Level 21
 
Posts: 15449
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Running screensaver and song at once

Postby Ertain on Wed Jan 18, 2012 3:10 pm

I have tried that, and that doesn't work, either.
Ertain
Level 1
Level 1
 
Posts: 14
Joined: Tue Jan 17, 2012 4:41 pm

Re: Running screensaver and song at once

Postby Ertain on Sun Jan 22, 2012 8:51 pm

I think I have finally figured out how to run the song. Here's the Perl code I used.
Code: Select all
my $cmd = "xscreensaver-command -watch";

open (IN, "$cmd |") or die "Couldn't run xscreensaver-command.\n";

# Log it
open (LOG, "/tmp/play_sound.txt");

print("xscreensaver-command for watch started.\n");

while (<IN>) {
if (m/^(BLANK|LOCK)/) {
    #when screensaver activates, run the following commands
    print("Playing song. \n");
    print LOG "--------------------------------------------------------------------\n";
    print LOG "started:\n";
    system("date >> /tmp/play_sound.txt");
    system("play \"/home/user/Music/le_music.mp3\" &");
    }
elsif (m/^UNBLANK/) {
  system("echo \"--------------------------------------------------------------------\" >> /tmp/play_sound.txt");
  print LOG "--------------------------------------------------------------------\n";
  system("echo \"stopped:\" >> /tmp/play_sound.txt");
  print LOG "stopped:\n";
  system("date >> /tmp/play_sound.txt");
  system("echo \"--------------------------------------------------------------------\" >> /tmp/play_sound.txt");
  print LOG "--------------------------------------------------------------------\n";
  print("Stopping song. \n");
  system("killall play");
   }
}

If I run this in some terminal or as some daemon, it'll work. More testing, however, is needed to see if this'll work as I want it.

Edit: this script mostly works. Whenever I suspend my machine and come back the screensaver comes on and, subsquently, the script activitated. Would be nice to check for things like that.
Ertain
Level 1
Level 1
 
Posts: 14
Joined: Tue Jan 17, 2012 4:41 pm

Re: [SOLVED... Mostly] Running screensaver and song at once

Postby äxl on Fri Apr 20, 2012 4:18 pm

I found this script on Gnome.org and Ubuntuforums. Gnome.org says idleness is now controlled by GnomeSession. So after finding Olivier Mehani's page and looking at the output of dbus-monitor I've reached this:
Code: Select all
#!/usr/bin/perl
#Gnome#
my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.SessionManager.Presence',member='StatusChanged'\"";
#KDE#my $cmd = "dbus-monitor --session \"type='signal',interface='org.freedesktop.ScreenSaver',member='ActiveChanged'\"";
#MATE#my $cmd = "dbus-monitor --session \"type='signal',interface='org.mate.SessionManager.Presence',member='StatusChanged'\"";

open (IN, "$cmd |");

while (<IN>)
{
#KDE#if (m/^\s+boolean true/)
#Gnome/MATE#
   if (m/^\s+uint32 3/)
   {
#when session idles these commands will run
      system("COMMAND");
      system("COMMAND"); #you can add system("COMMAND"); lines at will
   }
#KDE#elsif (m/^\s+boolean false/)
#Gnome/MATE#
   elsif (m/^\s+uint32 0/)
   {
#when session is active again these commands will run
      system("COMMAND");
      system("COMMAND"); #delete these two system lines if not wanted/needed
   }
}

You have to replace COMMAND with what you want to achieve of course. You can add an echo before the command to try the script.

Ertain, I don't know if it comes on after suspend. Thanks for the KDE call though provided it still works. ;) Maybe someone knows bus commands from other environments?

I've added a launcher to autostart with "perl script.pl" and it's works brilliantly. I'm running xrandr to turn my CRT's brightness to 0.3.
But I guess since nobody uses CRTs anymore xbacklight would be the fitting tool, right?
I removed the screensaver and power manager. I set up my idle time with my configuration editor and use DPMS to turn the screen off.
Have not found out so far how to disable Gnome screen locking. GnomeSession also goes 'inhibited' (uint32 8/) after some seconds if someone wants to call for that.

Also I don't know how to let the script sleep/wait before another command ... I've tried sleep() everywhere ... Maybe another while loop or just adding something like +60 ...?
My Linux history: Ubuntu 10.04 - 10.10 - LMDE 201109 - UP4 My sources.list/preferences

Computers is not science. And it's not magic - it's something in between.
User avatar
äxl
Level 5
Level 5
 
Posts: 524
Joined: Fri Apr 06, 2012 6:14 am
Location: Germany

Re: [SOLVED... Mostly] Running screensaver and song at once

Postby Ertain on Sun Apr 29, 2012 12:09 am

Sorry, äxl, I've been away for a while. I'll take a look into this newer script. Thank you for the reply, btw. :wink:
Ertain
Level 1
Level 1
 
Posts: 14
Joined: Tue Jan 17, 2012 4:41 pm


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 3 guests