gconftool-2
コマンドラインから壁紙を変更する方法。 gconftool-2コマンドを使用することで設定を変更・取得することができる。 まずは壁紙ファイルの設定方法から。
gconftool-2 --type string --set "/desktop/gnome/background/picture_filename" ファイル名
続いて、壁紙の配置スタイルの設定方法。
gconftool-2 --type string --set "/desktop/gnome/background/picture_options" スタイル
ちなみに、次のスタイルを適用することができる。
- scaled(等幅サイズ変更)
- stretched(フルスクリーン)
- centered(中央に配置)
- wallpaper(サイズ均等、並べて表示)
設定を取得するには--setではなく--getオプションを使用する。
gconftool-2 --get "/desktop/gnome/background/picture_options
壁紙変更スクリプト(改良版)
ディレクトリにあるファイルからランダムにファイルを選択して壁紙に設定するスクリプト。 設定した壁紙をログに記録するようにして一度設定した壁紙は、ディレクトリ内の全てのファイルを一巡するまで選択されない。
#!/usr/bin/perl
# 以前に設定した壁紙ファイルのリストを保持するログファイル
my $wallpaper_log = '.wallpaper.log';
# 壁紙ファイルのリストを取得する
my @wallpapers = `ls /home/santamarta/wallpapers/*.*`;
if ( $#wallpapers == 0 ) {
print "no wallpapers\n";
exit 0;
}
# 以前に設定した壁紙ファイルのリストを取得する
my @alreadies = ();
if ( -e $wallpaper_log ) {
open( INPUT, "<$wallpaper_log" ) or die;
@alreadies = <INPUT>;
close( INPUT );
# 壁紙ファイルの一覧から、以前に設定した壁紙ファイルを削除する
foreach $already ( @alreadies ) {
@wallpapers = grep( !/ $already/, @wallpapers );
}
# 壁紙ファイルの一覧が1になってしまったら、以前に設定した
# 壁紙ファイルのリストを削除する
if ( $#wallpapers <= 0 ) {
unlink( $wallpaper_log );
}
}
# 壁紙ファイルの一覧からランダムに1つだけ選び出す
my $wallpaper = $wallpapers[int( rand( $#wallpapers ) )];
# 選び出した壁紙ファイルを設定する
# ($wallpaperはフルパス形式になっていないと壁紙が描画されない)
$result = `gconftool-2 --type string --set "/desktop/gnome/background/picture_filename" $wallpaper`;
# 選び出した壁紙ファイルを、以前に設定した壁紙ファイルのリストに追加する
open( OUTPUT, ">>$wallpaper_log" ) or die;
print OUTPUT "$wallpaper";
close( OUTPUT );
exit 0;
GNOME 2.18.1(Ubuntu 7.04)にて動作確認済み。
壁紙変更スクリプト
ディレクトリにあるファイルからランダムに選択して壁紙を変更するスクリプト。
#!/bin/sh
WALLPAPERS="/home/santamarta/wallpapers/*.png"
# 壁紙ファイルを配列に格納
declare -a wallpaperFiles
for file in $WALLPAPERS
do
if [ wallpaperFiles[0] == "" ]; then
wallpaperFiles[0]=$file
else
wallpaperFiles[${#wallpaperFiles[*]}]=$file
fi
done
# 壁紙ファイルをランダムに選び出す
wallpaperFile=${wallpaperFiles[`expr $RANDOM % ${#wallpaperFiles[*]}`]}
# 選んだ壁紙ファイルを適用する
gconftool-2 --type string --set "/desktop/gnome/background/picture_filename" $wallpaperFile