实现原理是使用一个xml文件来记录可供切换选择的壁纸。下面展示的是10.04中自带的一个样例。
首先说明一下,ubuntu默认的壁纸存放在/usr/share/backgrounds/目录下的,在该目录中还有一个cosmos(意思是“宇宙”)目录,cosmos里面的xml文件就是实现动态桌面壁纸切换功能的了。
本脚本就是对给定图片文件夹快速生成相应 xml配置文件。
现在关键是生成相应的xml 配置文件了,里面的类容比较繁杂,手动更新太麻烦了,所以想到以脚本实现。
1. perl 写成的源代码如下:
#!/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 PM
Updated : 08/18/2010 09:51:11 PM
LastMod : ---
=head1 Contact
Author : QuNengrong (Qunero)
E-mail : Quner612@qq.com,QuNengrong@genomics.cn
Company : BGI
=cut
#-------------------------------help-info-end--------------------------------#
#============================================================================#
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 /./ to /
$_ =~ 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</hour>
<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";
}
脚本使用简单说明:
1. 运行时最好使用完整路径,指明 图片所在的目录, 例如:
getBackgroundXML.pl -d pathtowallpaper/Windows7/ -o Windows7/background.xml
2. 默认 图片文件路径为当前目录 ,文件类型为 jpg, 默认输出结果到终端,保存需加上 -o filename;
3. 设置好后的应用方法:右键桌面->更改桌面背景->添加,在弹出对话框的右下方那里选择“全部文件”(默认是“图像”),然后找到你定义好的动态桌面壁纸的xml文件,双击添加就可以了。
4. 感兴趣的实验 :
1)加入可选参数 -t 指定切换时间,默认半小时左右。
2)优化代码,让其可移植性更好~~
5. 附件可以去ubuntu论坛下载,以及几张漂亮的window7图片 ,background.xml 需要根据你的路径修改后在使用~~,祝大家玩得开心、用得顺手!
附件和源码下载,请见ubuntu 论坛:
http://forum.ubuntu.org.cn/viewtopic.php?f=21&t=289599
分享到:
相关推荐
在ubuntu16.04运行lsd-slam需要一些修改,该文件为修改后的文件,参考http://www.luohanjie.com/2017-03-17/ubuntu-install-lsd-slam.html进行安装运行,如果运行有问题,可参考下面几个链接: ubuntu16.04/linux...
本文介绍了vue学习之mintui picker选择器实现省市二级联动示例,分享给大家,具体如下: Mint UI 使用文档:https://mint-ui.github.io/docs/#/zh-cn2 Popup弹出框介绍:...
ubuntu安装todesk
该项目是一个安装脚本,它允许在一个命令中安装编程语言,二进制文件和实用程序! 支持的操作系统 的Ubuntu Linux Mint 安装 以下示例显示如何使用安装脚本: curl -s ' ...
用于32位UEFI启动Ubuntu LinuxMint 等等系统安装后的EFI.zip
Linux Mint 17官方壁纸
实测fedora 33 linux mint 20 可以使用,ubuntu 20.04 更能用,是原生版,不是wine版,下载解压以后看readme.txt文件,安装完成记得重启或注销。真情奉送。
将安装常用应用程序的构建脚本,默认情况下未安装在 Ubuntu/Ubuntu 版本上 评论:此脚本包含基于 debian 和基于 ubuntu 的发行版的安装命令,即 Ubuntu (proper)、Ubuntu-Mate、Xubuntu、Kubuntu、Ubuntu Budgie、...
该bash脚本是为Linux Mint和Ubuntu编写的,它将在新计算机上安装所有必需的软件。 主要的创新之处在于,该脚本始终使用apt,snap或自定义的bash脚本安装最新的可用版本。 对于R用户,它也可以安装RStudio首选项和R...
包装脚本/代码以与进行交互。用作一部分 要求: mintable ( npm install -g mintable ) whiptail (通常可安装为newt或libnewt ) figlet bash 4.0+ python 3.7+ 我使用来获取帐户信息,并将其导出到本地CSV...
主要通过 Mint-ui 前端框架实现页面左右切换,有点内容高度不固定,根据页面内容自动计算。 代码示例如下:如需要查看详细代码,请下载完整示例。 cnpm i mint-ui -S -D // 按需引入部分组件 import { ...
下载并解压到项目文件夹下,使用npm install安装依赖,使用npm run serve命令启动项目。
使用方法: 1. 解压文件,得到 apt目录。 2. sudo mv /etc/apt et/apt.old 3. sudo mv ./apt /etc/apt 4. sudo apt update 完成:注意,仅适用于linux mint ubuntu系列.
主要介绍了Ubuntu、Linux Mint一键安装Chrome浏览器的Shell脚本分享,本文直接给出实现代码,需要的朋友可以参考下
gtk-murrine引擎Fedora/RedHat gtk2-engines-murrine Ubuntu/Mint/Debian gtk-engine-murrine Arch/ManjaroGTK2 pixbuf引擎要求。 gtk2-engine Fedora/RedHat gtk2-engines-pixbuf Ubuntu/Mint/Debian gtk-engines ...
gtk2-engines-murrine Ubuntu/Mint/Debian gtk-engine-murrine Arch/Manjaro GTK2 pixbuf引擎要求。 gtk2-engine Fedora/RedHat gtk2-engines-pixbuf Ubuntu/Mint/Debian gtk-engines Arch/Manjaro 已安装的...
ubuntu/Mint各桌面环境下通用 ,有五笔,拼音,google拼音等,注意终端输入前把源设置为国内163/阿里云等
perl食谱 管理Perl安装并提供...要求平台类Debian / Ubuntu / Mint RHEL / CentOS /科学/亚马逊/ Oracle 软呢帽openSUSE 视窗厨师厨师13.4+食谱没有菜谱default -在Linux上安装perl软件包并从Github中提取cpanm。 在Wi
vue2.0+mintUI 实现的微信公众号投票系统前端框架代码,可使用模拟数据测试。 npm install 安装,npm run dev 启动 调试端口8087
因为 在webpack.config中没有设置好css引入的目录,因为默认情况下我们只会引入/src/目录下的css, 但是mint-ui是要冲node_modules目录去引入的,所以在webpack.config中css的配置中加入一项 { test: /\.css$/