#随机序列幻灯式演示, 关闭: 按两次 ALT+F4
#!/bin/bash
if [[ $# -lt 1 ]];then
echo 写入文件夹完整地址参数! 例:./prv.sh ~/Pictures/share/;
exit 0;
fi;
v_dir=$*;
if (echo $v_dir |grep -q '.*/.*');then
v_dir=$v_dir;
else
v_dir=$PWD;
fi;
if [[ ${v_dir:$((${#v_dir}-1)):1} != / ]];then
v_dir=$v_dir/;
fi;
v_picture_count=0;
for i in $(ls $v_dir);do
((v_picture_count++));
a_picture_name[$v_picture_count]=$i;
done;
for i in $(seq $v_picture_count);do
v_tmp=${a_picture_name[$i]};
v_random=$(($RANDOM%$v_picture_count+1));
a_picture_name[$i]=${a_picture_name[$v_random]};
a_picture_name[$v_random]=$v_tmp;
done;
i=1;
while [[ $i -le $v_picture_count ]];do
eog -fn $v_dir${a_picture_name[$i]}&
((i++));
if [[ $i -gt $v_picture_count ]];then
i=1;
for i in $(seq $v_picture_count);do
v_tmp=${a_picture_name[$i]};
v_random=$(($RANDOM%$v_picture_count+1));
a_picture_name[$i]=${a_picture_name[$v_random]};
a_picture_name[$v_random]=$v_tmp;
done;
fi;
sleep 3;
if [[ $(ps aux |grep -c eog) -eq 1 ]];then
exit 0;
else
v_eog=$(ps aux |grep eog |grep -v '\bgrep\b' |head -1);
v_eog=$(echo $v_eog |awk -F" " '{print $2}');
if [[ $(ps aux |grep -c eog) -gt 2 ]];then
kill $v_eog;
fi;
fi;
done;
简单随机幻灯脚本
-
- 帖子: 919
- 注册时间: 2009-07-01 22:04
-
- 帖子: 919
- 注册时间: 2009-07-01 22:04
Re: 简单随机幻灯脚本
#!/bin/bash
#修正版,改正了鼠标右键在非home分区不能打开图片的bug.
if [[ $# -lt 1 ]];then
echo 写入文件夹完整地址参数! 例: $0 ~/Pictures/share/;
exit 1;
fi;
if (echo "$*" |grep -q '.*/.*');then
v_dir=$*;
else
v_dir=$PWD;
fi;
if [[ ${v_dir:$((${#v_dir}-1)):1} != / ]];then
v_dir=$v_dir/;
fi;
v_picture_count=0;
for i in $(ls $v_dir);do
((v_picture_count++));
a_picture_name[$v_picture_count]=$i;
done;
f_random()
{
for i in $(seq $v_picture_count);do
v_tmp=${a_picture_name[$i]};
v_random=$(($RANDOM%$v_picture_count+1));
a_picture_name[$i]=${a_picture_name[$v_random]};
a_picture_name[$v_random]=$v_tmp;
done;
}
f_random;
i=1;
while [[ $i -le $v_picture_count ]];do
eog -fn $v_dir${a_picture_name[$i]}&
((i++));
if [[ $i -gt $v_picture_count ]];then
i=1;
f_random;
fi;
sleep 4;
if [[ $(ps aux |grep -c eog) -eq 1 ]];then
exit 0;
else
v_eog=$(ps aux |grep eog |grep -v '\bgrep\b' |head -1);
v_eog=$(echo $v_eog |awk -F" " '{print $2}');
if [[ $(ps aux |grep -c eog) -gt 2 ]];then
kill $v_eog;
fi;
fi;
done;
#修正版,改正了鼠标右键在非home分区不能打开图片的bug.
if [[ $# -lt 1 ]];then
echo 写入文件夹完整地址参数! 例: $0 ~/Pictures/share/;
exit 1;
fi;
if (echo "$*" |grep -q '.*/.*');then
v_dir=$*;
else
v_dir=$PWD;
fi;
if [[ ${v_dir:$((${#v_dir}-1)):1} != / ]];then
v_dir=$v_dir/;
fi;
v_picture_count=0;
for i in $(ls $v_dir);do
((v_picture_count++));
a_picture_name[$v_picture_count]=$i;
done;
f_random()
{
for i in $(seq $v_picture_count);do
v_tmp=${a_picture_name[$i]};
v_random=$(($RANDOM%$v_picture_count+1));
a_picture_name[$i]=${a_picture_name[$v_random]};
a_picture_name[$v_random]=$v_tmp;
done;
}
f_random;
i=1;
while [[ $i -le $v_picture_count ]];do
eog -fn $v_dir${a_picture_name[$i]}&
((i++));
if [[ $i -gt $v_picture_count ]];then
i=1;
f_random;
fi;
sleep 4;
if [[ $(ps aux |grep -c eog) -eq 1 ]];then
exit 0;
else
v_eog=$(ps aux |grep eog |grep -v '\bgrep\b' |head -1);
v_eog=$(echo $v_eog |awk -F" " '{print $2}');
if [[ $(ps aux |grep -c eog) -gt 2 ]];then
kill $v_eog;
fi;
fi;
done;
bash不如perl精妙,学不到lisp的皮毛,远不够c++强悍,不过可以用。
-
- 帖子: 919
- 注册时间: 2009-07-01 22:04
Re: 简单随机幻灯脚本
#!/bin/bash
#双击运行版.
if [[ $# -lt 1 ]];then
v_dir=`zenity --file-selection --directory --title="请选择图片文件夹"`;
if [[ -z $v_dir ]];then
exit 1;
fi;
elif (echo "$*" |grep -q '.*/.*');then
v_dir=$*;
else
v_dir=$PWD;
fi;
if [[ ${v_dir:$((${#v_dir}-1)):1} != / ]];then
v_dir=$v_dir/;
fi;
v_picture_count=0;
for i in $(ls $v_dir);do
((v_picture_count++));
a_picture_name[$v_picture_count]=$i;
done;
f_random()
{
for i in $(seq $v_picture_count);do
v_tmp=${a_picture_name[$i]};
v_random=$(($RANDOM%$v_picture_count+1));
a_picture_name[$i]=${a_picture_name[$v_random]};
a_picture_name[$v_random]=$v_tmp;
done;
}
f_random;
i=1;
while [[ $i -le $v_picture_count ]];do
eog -fn $v_dir${a_picture_name[$i]}&
((i++));
if [[ $i -gt $v_picture_count ]];then
i=1;
f_random;
fi;
sleep 4;
if [[ $(ps aux |grep -c eog) -eq 1 ]];then
exit 0;
else
v_eog=$(ps aux |grep eog |grep -v '\bgrep\b' |head -1);
v_eog=$(echo $v_eog |awk '{print $2}');
if [[ $(ps aux |grep -c eog) -gt 2 ]];then
kill $v_eog;
fi;
fi;
done;
#双击运行版.
if [[ $# -lt 1 ]];then
v_dir=`zenity --file-selection --directory --title="请选择图片文件夹"`;
if [[ -z $v_dir ]];then
exit 1;
fi;
elif (echo "$*" |grep -q '.*/.*');then
v_dir=$*;
else
v_dir=$PWD;
fi;
if [[ ${v_dir:$((${#v_dir}-1)):1} != / ]];then
v_dir=$v_dir/;
fi;
v_picture_count=0;
for i in $(ls $v_dir);do
((v_picture_count++));
a_picture_name[$v_picture_count]=$i;
done;
f_random()
{
for i in $(seq $v_picture_count);do
v_tmp=${a_picture_name[$i]};
v_random=$(($RANDOM%$v_picture_count+1));
a_picture_name[$i]=${a_picture_name[$v_random]};
a_picture_name[$v_random]=$v_tmp;
done;
}
f_random;
i=1;
while [[ $i -le $v_picture_count ]];do
eog -fn $v_dir${a_picture_name[$i]}&
((i++));
if [[ $i -gt $v_picture_count ]];then
i=1;
f_random;
fi;
sleep 4;
if [[ $(ps aux |grep -c eog) -eq 1 ]];then
exit 0;
else
v_eog=$(ps aux |grep eog |grep -v '\bgrep\b' |head -1);
v_eog=$(echo $v_eog |awk '{print $2}');
if [[ $(ps aux |grep -c eog) -gt 2 ]];then
kill $v_eog;
fi;
fi;
done;
上次由 fnan 在 2011-03-05 23:20,总共编辑 1 次。
bash不如perl精妙,学不到lisp的皮毛,远不够c++强悍,不过可以用。
-
- 帖子: 186
- 注册时间: 2010-05-25 16:49
Re: 简单随机幻灯脚本
为什么不缩进 看的我头好疼
-
- 帖子: 919
- 注册时间: 2009-07-01 22:04
Re: 简单随机幻灯脚本
#!/bin/bash
#双击运行版.
if [[ $# -lt 1 ]];then
v_dir=`zenity --file-selection --directory --title="请选择图片文件夹"`;
if [[ -z $v_dir ]];then
exit 1;
fi;
elif (echo "$*" |grep -q '.*/.*');then
v_dir=$*;
else
v_dir=$PWD;
fi;
if [[ ${v_dir:$((${#v_dir}-1)):1} != / ]];then
v_dir=$v_dir/;
fi;
v_picture_count=0;
for i in $(ls $v_dir);do
((v_picture_count++));
a_picture_name[$v_picture_count]=$i;
done;
f_random()
{
for i in $(seq $v_picture_count);do
v_tmp=${a_picture_name[$i]};
v_random=$(($RANDOM%$v_picture_count+1));
a_picture_name[$i]=${a_picture_name[$v_random]};
a_picture_name[$v_random]=$v_tmp;
done;
}
f_random;
i=1;
while [[ $i -le $v_picture_count ]];do
eog -fn $v_dir${a_picture_name[$i]}&
((i++));
if [[ $i -gt $v_picture_count ]];then
i=1;
f_random;
fi;
sleep 4;
if [[ $(ps aux |grep -c eog) -eq 1 ]];then
exit 0;
else
v_eog=$(ps aux |grep eog |grep -v '\bgrep\b' |head -1);
v_eog=$(echo $v_eog |awk '{print $2}');
if [[ $(ps aux |grep -c eog) -gt 2 ]];then
kill $v_eog;
fi;
fi;
done;
# 不能加缩进,重发一次。
#双击运行版.
if [[ $# -lt 1 ]];then
v_dir=`zenity --file-selection --directory --title="请选择图片文件夹"`;
if [[ -z $v_dir ]];then
exit 1;
fi;
elif (echo "$*" |grep -q '.*/.*');then
v_dir=$*;
else
v_dir=$PWD;
fi;
if [[ ${v_dir:$((${#v_dir}-1)):1} != / ]];then
v_dir=$v_dir/;
fi;
v_picture_count=0;
for i in $(ls $v_dir);do
((v_picture_count++));
a_picture_name[$v_picture_count]=$i;
done;
f_random()
{
for i in $(seq $v_picture_count);do
v_tmp=${a_picture_name[$i]};
v_random=$(($RANDOM%$v_picture_count+1));
a_picture_name[$i]=${a_picture_name[$v_random]};
a_picture_name[$v_random]=$v_tmp;
done;
}
f_random;
i=1;
while [[ $i -le $v_picture_count ]];do
eog -fn $v_dir${a_picture_name[$i]}&
((i++));
if [[ $i -gt $v_picture_count ]];then
i=1;
f_random;
fi;
sleep 4;
if [[ $(ps aux |grep -c eog) -eq 1 ]];then
exit 0;
else
v_eog=$(ps aux |grep eog |grep -v '\bgrep\b' |head -1);
v_eog=$(echo $v_eog |awk '{print $2}');
if [[ $(ps aux |grep -c eog) -gt 2 ]];then
kill $v_eog;
fi;
fi;
done;
# 不能加缩进,重发一次。
bash不如perl精妙,学不到lisp的皮毛,远不够c++强悍,不过可以用。
-
- 帖子: 919
- 注册时间: 2009-07-01 22:04
-
- 帖子: 919
- 注册时间: 2009-07-01 22:04
Re: 简单随机幻灯脚本
代码: 全选
#!/bin/bash
#双击运行版.
if [[ $# -lt 1 ]];then
v_dir=`zenity --file-selection --directory --title="请选择图片文件夹"`;
if [[ -z $v_dir ]];then
exit 1;
fi;
elif (echo "$*" |grep -q '.*/.*');then
v_dir=$*;
else
v_dir=$PWD;
fi;
if [[ ${v_dir:$((${#v_dir}-1)):1} != / ]];then
v_dir=$v_dir/;
fi;
v_picture_count=0;
for i in $(ls $v_dir);do
((v_picture_count++));
a_picture_name[$v_picture_count]=$i;
done;
f_random()
{
for i in $(seq $v_picture_count);do
v_tmp=${a_picture_name[$i]};
v_random=$(($RANDOM%$v_picture_count+1));
a_picture_name[$i]=${a_picture_name[$v_random]};
a_picture_name[$v_random]=$v_tmp;
done;
}
f_random;
i=1;
while [[ $i -le $v_picture_count ]];do
eog -fn $v_dir${a_picture_name[$i]}&
((i++));
if [[ $i -gt $v_picture_count ]];then
i=1;
f_random;
fi;
sleep 4;
if [[ $(ps aux |grep -c eog) -eq 1 ]];then
exit 0;
else
v_eog=$(ps aux |grep eog |grep -v '\bgrep\b' |head -1);
v_eog=$(echo $v_eog |awk '{print $2}');
if [[ $(ps aux |grep -c eog) -gt 2 ]];then
kill $v_eog;
fi;
fi;
done;
bash不如perl精妙,学不到lisp的皮毛,远不够c++强悍,不过可以用。
-
- 帖子: 274
- 注册时间: 2006-12-18 1:05
Re: 简单随机幻灯脚本
能不能暂停?
-
- 帖子: 919
- 注册时间: 2009-07-01 22:04
Re: 简单随机幻灯脚本
代码: 全选
#!/bin/bash
#按 F1 暂停,再按继续,找不到后台进程检察按键的方法。
if [[ $# -lt 1 ]];then
v_dir=`zenity --file-selection --directory --title="请选择图片文件夹"`
if [[ -z $v_dir ]];then
exit 1
fi;
elif (echo "$*" |grep -q '.*/.*');then
v_dir=$*
else
v_dir=$PWD
fi
if [[ ${v_dir:$((${#v_dir}-1)):1} != / ]];then
v_dir=$v_dir/
fi
v_picture_count=0
for i in $(ls $v_dir);do
((v_picture_count++))
a_picture_name[$v_picture_count]=$i
done
f_random()
{
for i in $(seq $v_picture_count);do
v_tmp=${a_picture_name[$i]}
v_random=$(($RANDOM%$v_picture_count+1))
a_picture_name[$i]=${a_picture_name[$v_random]}
a_picture_name[$v_random]=$v_tmp
done
}
f_gnome_help()
{
[[ $(pgrep -c gnome-help) -ne 0 ]]
}
f_kill_gnome_help()
{
kill $(pgrep gnome-help)
}
f_random
i=1
f_gnome_help
if [[ $? -eq 0 ]];then
f_kill_gnome_help
fi
if [[ $(pgrep -cx eog) -gt 0 ]];then
killall eog
fi
while [[ $i -le $v_picture_count ]];do
f_gnome_help
if [[ $? -eq 0 ]];then
f_kill_gnome_help
sleep 0.3
while [[ $(pgrep -c gnome-help) -eq 0 ]];do
sleep 0.3
done
sleep 0.2
fi
f_gnome_help
if [[ $? -eq 0 ]];then
f_kill_gnome_help
fi
eog -fn $v_dir${a_picture_name[$i]}&
((i++))
if [[ $i -gt $v_picture_count ]];then
i=1
f_random
fi
sleep 3
if [[ $(pgrep -cx eog) -eq 0 ]];then
exit 0
else
v_eog=$(pgrep -ox eog)
if [[ $(pgrep -cx eog) -gt 1 ]];then
kill $v_eog
fi
fi
done
bash不如perl精妙,学不到lisp的皮毛,远不够c++强悍,不过可以用。