Find the answer to your Linux question:
Results 1 to 6 of 6
Well I love simple Window Managers like kahakai and I always set my wallpaper using hsetroot -fill image.jpg, so I decided to write a little app so it would go ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User
    Join Date
    Nov 2003
    Location
    Brooklyn, NY
    Posts
    347

    Need some basic Perl help


    Well I love simple Window Managers like kahakai and I always set my wallpaper using hsetroot -fill image.jpg, so I decided to write a little app so it would go to my wallpaper dir do ls and ask me which wallpaper do I want set:

    Code:
    print "The following wallpapers are in your Wallpaper dir:\n";
    system("cd /files/Image/Wallpapers && ls");
    print "What file to use as wallpaper > ";
    $bg = <STDIN>;
    chomp $bg;
    system&#40;"hsetroot -fill $bg"&#41;;
    print "$bg is set now set as your wallpaper\n";
    When I run it, I get:
    Code:
    slip@localhost perl $ perl wallpaper.pl
    The following wallpapers are in your Wallpaper dir&#58;
    2065.gif                       Thumbs.db
    2a-expansions01-1600x1200.jpg  breed.jpg
    370_1600.jpg                   depth.jpg
    Alpha_and_Omega.jpg            fckRiotrend.jpg
    Archiplex.jpg                  formation6_wallpaper.jpg
    Blood_Letting.jpg              funny-hair-03-red_1600.gif
    Chemical Warfare.jpg           junksick.jpg
    Crimson_Skies.jpg              micro.jpg
    GeoFail.jpg                    no!se.jpg
    Lifes_Too_Short.jpg            noise.jpg
    StolenMoments_1600.jpg         welt.jpg
    The_Collapse_of_Deciduous.jpg
    What file to use as wallpaper > junksick.jpg
    Bad image &#40;junksick.jpg&#41;
    junksick.jpg is set now set as your wallpaper
    It does not set the wallpaper and if I would do hsetroot -fill junksick.jpg in terminal it would set it as wallpaper. Any idea?

  2. #2
    Linux Newbie
    Join Date
    Aug 2001
    Location
    USA, Texas
    Posts
    217
    The problem is the way you are going to the image directory and listing the image files. Whenever you using the system() call it opens a shell and executes the commands you requested ( that is my understating anyway ). When the shell is done executing the requested commands it exits. So basically the shell is moving to the directory with the cd command but the $PWD of your perl script process is still in the directory where you started it. So instead of using the system() call to change the directory use chdir() instead.

    Code:
    print "The following wallpapers are in your Wallpaper dir&#58;\n";
    chdir&#40;"/files/Images/Wallpapers"&#41;;
    system&#40;"ls"&#41;;
    print "What file to use as wallpaper > ";
    $bg = <STDIN>;
    chomp $bg;
    system&#40;"hsetroot -fill $bg"&#41;;
    print "$bg is set now set as your wallpaper\n";
    There are better ways of doing the system("ls") line, but I assume that you just want something that works and I will only get into that if you ask.

    Hope that helps.
    [ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
    /* Don\'t make me use it! */

  3. #3
    Linux User
    Join Date
    Nov 2003
    Location
    Brooklyn, NY
    Posts
    347
    Thank you but the ls part actually worked just fine, the setting actuall background is where the problem is at. I just tried your way and actually it did not give me the lsit of the right files, just files in that dir where the script is in. When it comes to setting the wallpaper I still get that same problem.

  4. #4
    Linux Newbie
    Join Date
    Aug 2001
    Location
    USA, Texas
    Posts
    217
    The ls part only worked because it was part of the same shell as the 'cd' ... anyway another solution is to just use the full path to the image file.

    Code:
    print "The following wallpapers are in your Wallpaper dir&#58;\n";
    system&#40;"cd /files/Image/Wallpapers && ls"&#41;;
    print "What file to use as wallpaper > ";
    $bg = <STDIN>;
    chomp $bg;
    system&#40;"hsetroot -fill /files/Image/Wallpapers/$bg"&#41;;
    print "$bg is set now set as your wallpaper\n";
    see if that works for you.
    [ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
    /* Don\'t make me use it! */

  5. #5
    Linux User
    Join Date
    Nov 2003
    Location
    Brooklyn, NY
    Posts
    347
    Ah! That works, thanks!

  6. #6
    Linux Guru sarumont's Avatar
    Join Date
    Apr 2003
    Location
    /dev/urandom
    Posts
    3,682
    To modify what sykkn said, you could also set a variable to the path and just use system( "ls $path" ) and $path/$bg when you set your image.

    Side note: I love kahakai.
    "Time is an illusion. Lunchtime, doubly so."
    ~Douglas Adams, The Hitchhiker's Guide to the Galaxy

Posting Permissions

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