I am very new to Perl and this is the first program I've written that I consider to be useful.
The program selects a random image to be used as a background for IceWM by editing the relevant line in ~/.icewm/preferences. It then checks to see if IceWM is running. If it is, it restarts icewmbg. If it is not, it starts icewm-session.
I've edited my .xinitrc file to call this program on startx and I have also added "F2 = icewmRandombg" to my ~/.icewm/keys file so pressing F2 gives me a new background.
I'm fairly certain the second chdir command isn't necessary, but I'm not absolutely certain, and it's not hurting anything, so I left it. I put it there so icewm-session would be called from my home directory.
#!/usr/bin/perl -w # This program edits ~/.icewm/preferences to set a random wallpaper. # It then checks to see if IceWM is running. If it is, it restarts # icewmbg. If it isn't it starts icewm-session. use strict; my $image_directory = "/home/jivy/media/images/wallpaper"; my @image_files = glob "$image_directory/*"; my $wallpaper = $image_files[rand @image_files]; chdir "/home/jivy/.icewm" or die "Cannot change to .icewm: ($!)"; my $pref = "preferences"; my $new_pref = "preferences.tmp"; my $bak = "preferences.bak"; open PREF, "< $pref"; open NEW_PREF, ">> $new_pref"; while (<PREF>) { s#$image_directory/.*#$wallpaper"#; print NEW_PREF $_; } close PREF; close NEW_PREF; rename ($pref,$bak); rename($new_pref,$pref); chdir "/home/jivy" or die "Cannot change to jivy: ($!)"; if (`ps -e | grep icewm-session`) { exec "icewmbg -r"; } else { exec "icewm-session"; }
In reply to Random Desktop Background for IceWM by Texadan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |