Skip to content

Instantly share code, notes, and snippets.

@masaakif
Created November 29, 2013 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masaakif/7702730 to your computer and use it in GitHub Desktop.
Save masaakif/7702730 to your computer and use it in GitHub Desktop.
CentOSで壁紙を変更するシェルスクリプト
#!/bin/bash
function export_variables
{
pid=$(pgrep -u `whoami` gnome-panel )
for dbusenv in $pid; do
DBUS_SESSION_BUS_ADDRESS=$( grep -z DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//' )
data="DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS"
eval " export $data"
done
}
WALLPAPERS="/home/masaf/wallpapers/*"
# 壁紙ファイルを配列に格納
declare -a wallpaperFiles
current=$(gconftool-2 --get "/desktop/gnome/background/picture_filename")
echo $(date "+%Y/%m/%d %H:%M:%S") "current wallpaper is $current"
for file in $WALLPAPERS
do
if [ $file != $current ]; then
if [ wallpaperFiles[0] == "" ]; then
wallpaperFiles[0]=$file
else
wallpaperFiles[${#wallpaperFiles[*]}]=$file
fi
fi
done
# 壁紙ファイルをランダムに選び出す
wallpaperFile=${wallpaperFiles[`expr $RANDOM % ${#wallpaperFiles[*]}`]}
# 選んだ壁紙ファイルを適用する
export_variables
gconftool-2 --type string --set "/desktop/gnome/background/picture_filename" $wallpaperFile
gconftool-2 --type string --set "/desktop/gnome/background/picture_options" zoom
echo $(date "+%Y/%m/%d %H:%M:%S") "changed to $wallpaperFile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment