shell切换壁纸脚本分享

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
langyxxl
帖子: 443
注册时间: 2012-01-17 22:17

shell切换壁纸脚本分享

#1

帖子 langyxxl » 2012-10-31 19:37

shell脚本版块是不是可以开一个分享shell脚本的地方出来,大家把自己觉得有用的脚本分享出来,方便更多的人来学习
新手学shell脚本往往觉得枯燥,提供一些实际的例子有助于激发兴趣

我先分享一个ubuntu12.04 桌面壁纸1分钟自动随机切换的脚本出来

代码: 全选

#!/bin/bash

dir=/mnt/壁纸      #壁纸目录
cd $dir
i=0
for file in *.{jpg,png,bmp}   # 找到所有图片放入数组
do
	photos[i]=$file
	((i++))
done

while true                          #无限循环,切换壁纸
do
	((num=RANDOM%i))    #双小括号为运算
	gsettings set org.gnome.desktop.background picture-uri "file://$dir/${photos[$num]}"
	sleep 60
done

其他地方看一下应该就知道意思,我也就不废话了
上次由 langyxxl 在 2012-11-01 13:27,总共编辑 2 次。
funicorn
帖子: 1318
注册时间: 2005-09-13 4:56
系统: Ubuntu Jammy Jellyfi

Re: shell脚本分享

#2

帖子 funicorn » 2012-11-01 4:24

[bash]
#!/bin/bash
loop_wall(){
find $HOME/Pictures/Wall/ \( -type f -a -name \*.jpg -o -name \*.png \) | while read wall
do
ln -sf "$wall" "$HOME/.wallpaper"
sleep 300
done
}
touch $HOME/.wallpaper
gsettings set org.gnome.desktop.background picture-uri "file://$HOME/.wallpaper"

while true
do
loop_wall
done
[/bash]
头像
langyxxl
帖子: 443
注册时间: 2012-01-17 22:17

Re: shell脚本分享

#3

帖子 langyxxl » 2012-11-01 7:54

这个bash脚本是怎么放在网页上的?
头像
YeLee
论坛版主
帖子: 26406
注册时间: 2008-08-13 8:48
系统: Fundu i64
来自: 东海硇州,一双管钥。
联系:

Re: shell脚本分享

#4

帖子 YeLee » 2012-11-01 8:18

[bash]
#!/bin/bash
intertime=1800
wallpaper=/tmp/wallpaper
if [ -e $wallpaper ];then
exit 0
else
touch $wallpaper
fi

signal_handle()
{
rm $wallpaper
exit 1
}
trap signal_handle SIGHUP SIGINT SIGQUIT SIGABRT SIGKILL SIGALRM SIGTERM

while true
do
for i in $(find $1 -type f -name "*.png")
do
fvwm-root --retain-pixmap $i
sleep $intertime
if [ -z $(pgrep fvwm) ];then
rm $wallpaper
exit 0
fi
done
done

[/bash]
换壁纸啊。 :em01 :em01 :em01
◎当我站在道德的高度上俯视别人的时候,发现自己是多么渺小。
♥执着但不偏激,反对而不排斥,坚决捍卫矛盾体的存在方式。
★★★天气预报★★★
fcitx-yatable一个可以使用的码表输入法
[教程]几个实例攻克软件编译难关
Gentoo Development Guide
字体相关
头像
jarryson
帖子: 4002
注册时间: 2005-08-14 19:53

Re: shell脚本分享

#5

帖子 jarryson » 2012-11-01 9:06

不是自带壁纸程序就支持动态壁纸的嘛。。。
回复