Page 1 of 7 123 ... LastLast
Results 1 to 10 of 66

Thread: HOWTO: Adjust screensaver settings in Dapper

  1. #1
    Join Date
    Mar 2005
    Beans
    6,040

    HOWTO: Adjust screensaver settings in Dapper

    (Update - 17.12.06: This guide works in Edgy as well.)

    As you're probably aware, the gnome-screensaver GUI that ships with Dapper's GNOME 2.14.1 doesn't give the user any control on individual screensaver settings. I had previously posted a guide on replacing gnome-screensaver with xscreensaver, but it has a few drawbacks (which I listed in the linked thread) that some users may find deterrent. Hence the reason for this guide, which does the job in a more elegant but maybe slightly less convenient way.

    This will show you how to set preferences for your screensaver by figuring out the required command line with xscreensaver and putting it manually in the screensaver's gnome-screensaver theme file. It takes a bit more manual work, but I prefer this method over the other one since it doesn't have the drawbacks of replacing gnome-screensaver altogether, and it's more "technically correct".

    To compare, the other method is a bit more convenient if you adjust settings very often, but this one doesn't break anything and doesn't touch the Ubuntu defaults. It's up to you to decide which one to use.

    1. Install xscreensaver.
    Code:
    sudo apt-get install xscreensaver
    Note that unlike the other method, you won't actually be running xscreensaver full time; you'll only need its preferences interface to adjust screensaver settings to your liking and preview them.

    2. When you want to adjust the settings of a particular screensaver, launch the xscreensaver preferences dialog with
    Code:
    xscreensaver-demo
    and when asked whether you want to launch the daemon, click "Cancel". This is important, since running both the xscreensaver and gnome-screensaver daemons together is very likely to cause unwanted behavior.

    Choose the screensaver you want, click "Settings" to adjust its settings, and click "OK" to go back. In the Advanced" tab of the main window adjust image and text manipulation settings as you like. Check the preview area to see if it works the way you want, or hit "Preview" for a full screen preview. Once it's working as you want, click "Settings" and then "Advanced", and copy the string in the "Command Line" string box.

    3. Open the gnome-screensaver theme file that corresponds to your selected screensaver in /usr/share/gnome-screensaver/themes (in edgy this is /usr/share/applications/screensavers). For the Phosphor screensaver you'd have to do
    Code:
    gksudo gedit /usr/share/gnome-screensaver/themes/Phosphor
    Locate the line that begins with "Exec=" and replace the command that follows it with the command you copied from xscreensaver's "Command Line" box.

    4. Open the gnome-screensaver preferences window (System / Preferences / Screensaver) and choose your preferred screensaver there.

    5. Hit Alt+F2 and enter
    Code:
    gnome-screensaver-command --lock
    to test if the screensaver is behaving as you like.

    6. Optional: Install the extra screensavers in the repositories that don't come installed as default.
    Code:
    sudo apt-get install xscreensaver-data-extra xscreensaver-gl-extra
    For convenience you may want to use Alacarte or tweak the files in /usr/share/applications to create a separate Applications menu entry for xscreensaver called "Screensaver Settings" and rename the existing "Screensaver" item to "Screensaver Selection".
    Last edited by 23meg; December 23rd, 2007 at 12:39 AM.
    Previously known as 23meg

  2. #2
    Join Date
    Apr 2006
    Beans
    170

    Re: HOWTO: Adjust screensaver settings in Dapper

    Thank you 23 meg, I knew there must be a better way to do this. If I have some extra time I might make a bash script to "update" the gnome-screensaver config files to after running xscreensaver-demo. Basically, my idea would be to make the script open xscreensaver-demo, then, after xscreensaver exits, grep it's config files for "Exec=" and replace the line found in the xscreensaver config file, with the corrosponding one in the gnom-screensaver config file. The reason why I would have the script open xscreensaver-demo itself is so it could be added using alecarte as a menu item and violla: You click on the screensaver preference menue item as you normally would, edit the preferences in xscreensaver, and yet still be able to use gnome-screensaver. It would be completely transparent to the user if it weren't for the promt asking you to launch the demon.


    Note: I have NEVER made a bash script before, and although I have done some programming before, I am new to linux. I also may not have the time to make this script so if anyone is interested in making a script to do this, I don't see why it should be very hard for someone with more expierience, PLEASE don't wait for me to do it as I may never get to it. That is why I am posting this so that if I never get the ball rolling someone else can take off with it.
    Computers are like air-conditioners... neither work as well with Windows open.

  3. #3
    Join Date
    Mar 2005
    Beans
    6,040

    Re: HOWTO: Adjust screensaver settings in Dapper

    Thanks for the input; while testing some of the more obscure screensavers with this method today I was thinking of something along those lines; not the exact methodology though. I'll get to it and see what I can do as soon as I get some free time.
    Previously known as 23meg

  4. #4
    Join Date
    Apr 2006
    Beans
    170

    Talking Re: HOWTO: Adjust screensaver settings in Dapper

    I have almost finished my program so I thought I would post what I have since I don't know when I'll get back to it.

    As far as I can tell all that I have to do to make this work is to change the changeCommand method to work even if TrExec= ( the command used to preview a screensaver ) comes before Exec= as it is searching for Exec= which is in TrExec=. I would fix the problem now but it is late and bad things happen when I try to program tired. So here it is ( in java ) for anyone that is curious or would like to make any suggestions ( just please don't run it, I am not posting the .class file because this is unfinished and needs to run as root, so if it breaks it could be very bad and I take no responsability ) that being said, to run it run
    Code:
    sudo java ConfigSaver ~/.screensaver
    Code:
    import java.io.*;
    public class ConfigSaver{
        public static String pathToGnomeThemes = "/usr/share/gnome-screensaver/themes/";
        public static void main(String[] args){
            String xscreensaver = readFile(args[0]);
            // finds the names of all the screensavers by looking at thier .desktop filenames
            String[] screenSavers = getFileNames(pathToGnomeThemes);
            // strips the .desktop from the filename ( leaving only the name of the screensaver )
            for(int i=0; i< screenSavers.length; i++){
                String temp = screenSavers[i];
                temp = temp.substring(0, temp.length()-8);
                screenSavers[i] = temp;
            }
            // edits the .desktop files to update the command
            for(int i=0; i< screenSavers.length; i++){
                String saverName = screenSavers[i];
                String command = getCommand(xscreensaver, saverName);
                if(command != null){
                    String saverConfig = readFile(pathToGnomeThemes + saverName + ".desktop");
                    String newSaverConfig = changeCommand(saverConfig,command);
                    writeFile(pathToGnomeThemes + saverName + ".desktop", newSaverConfig);
                }
            }
        }
    
        public static String readFile(String filePath){     
            try { 
                BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(filePath))); 
                String text=input.readLine();
                String line = input.readLine(); 
                while(line !=null){
                    text+= "\n"; 
                    text+=line;
                    line = input.readLine(); 
                } 
                return text; 
            } 
            catch(IOException e) { 
                e.printStackTrace(); 
                return null; 
            } 
        }
    
        public static boolean writeFile(String filePath,String text){    // returns true if successfull, false if write failed.
            try{ 
                String toOut = text; 
                PrintStream output = new PrintStream(new FileOutputStream(filePath)); 
                output.print(toOut); 
                output.close(); 
            }
            catch(IOException e){
                e.printStackTrace();
                return false;
            }
            return true;
        }
        
        public static String[] getFileNames(String directory){ 
            return new File(directory + ".").list(); 
        }
        
        public static String getCommand( String xscreensaver, String saverName){
            int startOfCommand = xscreensaver.indexOf(saverName);
            if(startOfCommand == -1){
                try{
                    return null;//return javax.swing.JOptionPane.showInputDialog(saverName + " doesn't seem to have a corrosponding xscreensaver, enter the command you would like gnome-screensaver to use then hit OK \n or hit cancel to not change the command");
                }
                catch(Exception e){ // I only expect an exception to be thrown if this is being run on the open source JVM that does not implement most of swing
                    System.out.println(saverName + " was not modified because there doesn't seem to be a corrosponding xscreensaver ( this is normal and nothing to worry about )");
                    return null;
                }
            }
            String temp = xscreensaver.substring(startOfCommand);
            int endOfCommand = temp.indexOf("\\n\\");
            String command = temp.substring(0,endOfCommand);
            // remove any hard returns from the command
            while( command.indexOf("\n") != -1 ){
                temp = command.substring(0,command.indexOf("\n"));
                command = temp + command.substring(command.indexOf("\n")+1);
            }
            // remove any \s from the command
            while( command.indexOf("\\") != -1 ){
                temp = command.substring(0,command.indexOf("\\"));
                command = temp + command.substring(command.indexOf("\\")+1);
            }
            // remove any tabs from the command
            while( command.indexOf("    ") != -1 ){
                temp = command.substring(0,command.indexOf("    "));
                command = temp + command.substring(command.indexOf("    ")+1);
            }
            // remove any consecutive spaces (removes only one space so, for instance "-option  1" would become "-option 1" and "-option       1" would also become "-option 1"
            while( command.indexOf("  ") != -1 ){
                temp = command.substring(0,command.indexOf("  "));
                command = temp + command.substring(command.indexOf("  ")+1);
            }
            return command;
        }
        
        public static String changeCommand(String saverConfig, String command){
            if(saverConfig.indexOf("Exec=")< saverConfig.indexOf("TryExec")){
                String configBeforeCommand = saverConfig.substring(0,saverConfig.indexOf("Exec=") -1);
                String temp = saverConfig.substring(saverConfig.indexOf("Exec="));
                String configAfterCommand = temp.substring(temp.indexOf("\n"));
                saverConfig = configBeforeCommand + "Exec=" + command + configAfterCommand;
            }
            else{
                int startIndexOfCommand = saverConfig.indexOf("TryExec=") + 8;
                String temp = saverConfig.substring(startIndexOfCommand);
                startIndexOfCommand += temp.indexOf("Exec="); //-1;
                temp = saverConfig.substring(startIndexOfCommand);
                String configBeforeCommand = saverConfig.substring(0,startIndexOfCommand);
                String configAfterCommand = temp.substring(temp.indexOf("\n"));
                saverConfig = configBeforeCommand + "Exec=" + command + configAfterCommand;
            }     
            return saverConfig;
        }
    }
    [edit] updated code to working version
    Last edited by n00bWillingToLearn; July 1st, 2006 at 11:41 PM.
    Computers are like air-conditioners... neither work as well with Windows open.

  5. #5
    Join Date
    Apr 2006
    Beans
    170

    Talking Re: HOWTO: Adjust screensaver settings in Dapper

    My program is now working perfectly ( as far as I can tell ) so if anyone has an installation they are willing to lose ( I don't see any way that my program could do anything other than screw up you screensavers but anything is possible and nobody other than me has tried it yet or looked at the code for possible bugs so don't run this on your main installation ) for instance on a liveCD or a spare computer / partition here are the steps to set this up:

    1. Install xscreensaver.
    Code:
    sudo apt-get install xscreensaver
    2. Download my program and the shell script to run it 3. make the script executeable:
    Code:
     chmod +x ~/ConfigSaver
    4. You should now have two new files in your home folder, 'Configsaver.class' and 'ConfigSaver'. ConfigSaver is the script that will run my program, all you need to do is double click it. You can move ConfigSaver anywhere you want but ConfigSaver.class should stay in your home folder. When you double click on ConfigSaver the xscreensaver preferences should open up and you can change the settings of the screensavers, when you close the xscreensaver window, a dialog should come up asking you for your password ( I am trying to find a way around this but I would like a confermation that the program works as is before I work on that) enter your password and hit OK and your preferences should now be updated in gnome-screensaver.
    Last edited by n00bWillingToLearn; July 5th, 2006 at 02:39 AM. Reason: Alacarte doesn't seem to like using multiple commands so I've changed the instructions to use a bash script instead.
    Computers are like air-conditioners... neither work as well with Windows open.

  6. #6
    Join Date
    Nov 2005
    Location
    New York, USA
    Beans
    1,223
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: HOWTO: Adjust screensaver settings in Dapper

    Great piece of work.

    Before I try installing this on a spare dapper machine, I was wondering where to put the file that I download from you. From the alacarte command, you seem to imply that it would go in my home directory in a directory named ConfigSaver. Is this correct? The path would look like this on my machine: /home/marty/ConfigSaver/ConfigSaver.class

    It's folks like you that help make this the best Linux distro out there.
    Using Ubuntu since Warty Warthog (4.10)
    32 bit 5.04>5.10>6.06>6.10>7.04>7.10>8.04>8.10>9.04>9.10
    64 bit 9.10 upgraded to 10.04>10.10>11.04>11.10>12.04>14.04

  7. #7
    Join Date
    Mar 2005
    Beans
    6,040

    Re: HOWTO: Adjust screensaver settings in Dapper

    Quote Originally Posted by n00bWillingToLearn
    My program is now working perfectly
    Thanks a lot for the effort, but it doesn't work here; the preferences I set with xscreensaver don't apply to gnome-screensaver. I'm investigating the reason; maybe it's due to my tweaked configuration.

    Also having to grant root privilege to the app isn't very elegant but I guess since it has to write to /usr there's no way around that, right?
    Previously known as 23meg

  8. #8
    Join Date
    Apr 2006
    Beans
    170

    Re: HOWTO: Adjust screensaver settings in Dapper

    Quote Originally Posted by 23meg
    Thanks a lot for the effort, but it doesn't work here; the preferences I set with xscreensaver don't apply to gnome-screensaver. I'm investigating the reason; maybe it's due to my tweaked configuration.

    Also having to grant root privilege to the app isn't very elegant but I guess since it has to write to /usr there's no way around that, right?
    I shouldn't have said perfectly because I havn't had anyone else test it or look at the code but it works for me. The command I gave doesn't work in Alacarte for me for some reason ( I was hoping that was a problem on my machine with Alacarte, either it's not, or my program really doesn't work ). Try entering the command directly into the terminal or try using this shell script http://trogdoor.googlepages.com/ConfigSaver ( you will have to change the permissions to make it executable ). As for the running as root, I agree completely and don't like it much either. It may be possible to just change the privaleges of the themes folder although I don't know if that would break anything else.

    Please try again entering the command into the terminal and, to be clear, the reason this should be run on a scratch computer is because, as root, it could break your entire system ( or give me complete controll over it without your knowlage ).

    If anyone could give input on wether or not it would be safe to change the permissions of the themes folder that would be great.

    If anyone could look over the code itself that would be wonderfull.
    Last edited by n00bWillingToLearn; July 5th, 2006 at 02:56 AM.
    Computers are like air-conditioners... neither work as well with Windows open.

  9. #9
    Join Date
    Apr 2006
    Beans
    170

    Re: HOWTO: Adjust screensaver settings in Dapper

    Quote Originally Posted by mgmiller
    Great piece of work.

    Before I try installing this on a spare dapper machine, I was wondering where to put the file that I download from you. From the alacarte command, you seem to imply that it would go in my home directory in a directory named ConfigSaver. Is this correct? The path would look like this on my machine: /home/marty/ConfigSaver/ConfigSaver.class

    It's folks like you that help make this the best Linux distro out there.
    ConfigSaver.class should go directly in your home folder and for some reason ( probably my fault ) the command I gave doesn't work in Alacarte so I have updated my instructions to use a simple bash script ( basically the same command except in a bash script instead of in Alacarte ) and to clarify things a little more.
    Computers are like air-conditioners... neither work as well with Windows open.

  10. #10
    Join Date
    Sep 2005
    Location
    Atlanta, GA
    Beans
    18
    Distro
    Ubuntu 6.06

    Re: HOWTO: Adjust screensaver settings in Dapper

    thanks to both of you for the HowTo and the app but i'm still left wondering...why aren't these settings just availible from within the gnome-screensaver dialog? 'few options, sane defaults,' okay i get it but i mean...c'mon...

Page 1 of 7 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •