Make your Ubuntu Desktop Wallpaper dynamically change

Source: Internet
Author: User
Tags glob perl script

Recently, I still had to worry about the dynamic change of Ubuntu Desktop background with only two directories. I searched for resources online and found an XML script generation tool. This is because an XML scripting language is required for dynamic changes. This Perl script is used to generate an XML script file. Procedure:
1. add the new background image and the image. put the pl file in a folder named background (custom); 2. to CP this directory to the/usr/share/backgrounds directory, sudo; 3.cd background; 4. sudo Perl getbackgroundxml. pl-T 1500-D. -o change. XML to generate. XML file; 5. right-click desktop-> change desktop background-> Add-> Find the directory-> show all files-> select change. XML 6. OK

The source code of getbackgroundxml. pl is as follows:

#! /Usr/bin/perl
#===================================================== ================================================ #
# ------------------------------- Help-Info-start --------------------------------#
# = Head1 name
#
# Getbackgroundxml. pl --> Generate the background. xml file to change Ubuntu background picture dynamiclly
#
# = Head1 usage
#
# Perl getbackgroundxml. PL [<Options>] [-D picdir = '. '] [-T timetolast = 1795.0] [-I interval = 5.0] [-O background. xml = stdout]
#
#-Help print this help to screen
#-A flag, if set, write all pictures to one XML file
#-D directory contains the jpgs, defalt :'.'
#-T time to change background picture, unit: seconds, default: 1795.0
#-I interval time spend to change the two pictures, default: 5.0
#-O Write result to a file, default: stdout
#
# = Head1 example
#
# Perl getbackgroundxml. pl-D windows7-T 25-I 5-O windows7.xml
# Perl getbackgroundxml. pl --
#
# = Head1 version
#
# Verion: 2.0
# Created: 08/18/2010 03:34:52
# Updated: 08/18/2010 09:51:11
# Lastmod :---
#
#
# = Head1 contact
#
# Author: qunengrong (qunero)
# E-mail: Quner612@qq.com, QuNengrong@genomics.cn
# Company: BGI
#
# = Cut
##=================================================== ============================================== #
Use strict;
Use warnings;
Use getopt: long;

My ($ need_help, $ out_file, $ picdir, $ timetolast, $ interval, $ allinone );
Getoptions (
"Help" =>/$ need_help,
"A" =>/$ allinone,
"D = s" =>/$ picdir,
"T = I" =>/$ timetolast,
"I = I" =>/$ interval,
"O = s" =>/$ out_file,
);

Die 'pod2text $ 0' if ($ need_help );

#===================================================== ============================================ #
# Global variable #
#===================================================== ============================================ #
My $ input_file = $ argv [0] If (exists $ argv [0]);
$ Picdir | = '.';
$ Timetolast | = 1795.0;
$ Interval | = 5.0;
$ Picdir = ~ S // $ //;
$ Picdir = ~ S //// g; # Replace space to/space;
# Print stderr "$0-d $ picdir-T $ timetolast/N ";
#===================================================== ============================================ #
# Main process #
#===================================================== ============================================ #

If (defined $ input_file)
{Open (stdin, '<', $ input_file) or die $ !; }
If (defined $ out_file)
{Open (stdout, '>', $ out_file) or die $ !; }

Print stderr "--- Program/T $0/tstarts -->". localtime (). "/N ";

# Step 01: getbackgroundxml
& Getbackgroundxml ();

Print stderr "--- Program/T $0/t ends -->". localtime (). "/N ";

#===================================================== ============================================ #
# Subroutines #
#===================================================== ============================================ #

Sub getbackgroundxml (){
# My @ picfiles = 'ls $ picdir | grep. jpg '; # It's better than glob, In case $ picdir is ~ /Subdir
My @ picfiles;
If ($ allinone ){
# @ Picfiles = glob ("$ picdir/*. jpg ");
@ Picfiles = 'Find $ picdir/-name "*/. jpg "';
}
Else {
@ Picfiles = glob ("$ picdir/*. jpg ");
}

# Print stderr "test files:/n/T", join ("/T", @ picfiles );
Chomp (@ picfiles );


If ($ picdir = ~ /^ ///){
For (@ picfiles ){
# $ _ = "$ Picdir/$ _"; # already full path;
$ _ = ~ S // G;
}

}
Else {# path start with./or ../or subdir/
My $ curdir = 'pwd ';
Chomp ($ curdir );
For (@ picfiles ){
$ _ = "$ Curdir/$ _";
$ _ = ~ S // G;
$ _ = ~ S //. // G; # change/.//
$ _ = ~ S ///[^ //] + //./. //; # change path/DIR/../anotherdir/to path/anotherdir/
}
}

# Print stderr join ("/N", @ picfiles );

My $ oldjpg = $ picfiles [-1];
Print stdout
"<Background>
<Starttime>
<Year> 2010 </year>
<Month> 08 </month>
<Day> 18 </day>
<Hour> 00 <Minute> 00 </minute>
<Second> 00 </second>
</Starttime>
<! -- This animation will start now. -->/N ";

For (@ picfiles ){
Printf stdout
"<Static>
<Duration> %. 1f </duration>
<File> $ oldjpg </File>
</Static>
<Transition>
<Duration> %. 1f </duration>
<From> $ oldjpg </from>
<To >$ _ </to>
</Transition>/N ", $ timetolast, $ interval;
$ Oldjpg =$ _;
}
Print "</background>/N ";
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.