【发布时间】:2018-07-23 03:55:40
【问题描述】:
我在 Linux Mint 中有一个墙纸更换器脚本,如下所示(在 crontab* 中运行)。如果分析的话,就是说如果随机图片的高度或者宽度大于屏幕宽度,那么就缩放ELSE不缩放,直接居中(这里有个条件)。
而且效果很好,我喜欢我的剧本。但是,我在 Windows 中找不到类似的东西,我想知道附近是否有人有类似的脚本,而不是我必须编写代码?
windows 壁纸的问题在于,没有选项可以不缩放低于宽度/高度屏幕的图片,同时缩放高于宽度/高度的图片。在 Linux 中也是同样的问题,但这就是我为此编写脚本的原因。
请不要回答我必须调整图像大小。我不需要。我在 Linux 中找到了解决方案,当然可以在 Windows 中自动执行此操作。只需要一个将进入任务计划程序的 VBS 或 PowerShell 脚本。
*2m 壁纸更改的 Crontab 注释:
*/2 * * * * bash /somewhere/wallpaper.sh
.
#!/bin/bash
DESKTOP=mate16
wallpaperFolder="your/wallpaper/folder/with/a/trailing/slash/"
wallpaperWidth="2560"
wallpaperHeight="1080"
# grab a random image
wallpaperImage="$(ls $wallpaperFolder | shuf -n1)"
wallpaperImage=$wallpaperFolder$wallpaperImage
# grab the width and the height of the picture
wallpaperWidth=`identify -format "%w" "$wallpaperImage" | tr -d ' '`
wallpaperHeight=`identify -format "%h" "$wallpaperImage" | tr -d ' '`
if [[ "$DESKTOP" = "gnome2" ]]; then
gconftool-2 -t string -s /desktop/gnome/background/picture_filename "$wallpaperImage"
fi
if [[ "$DESKTOP" = "gnome3" ]]; then
if [ $wallpaperImage_width -gt $wallpaperWidth -o $wallpaperImage_height -gt $wallpaperHeight ]; then
DISPLAY=:0 gsettings set org.gnome.desktop.background picture-options scaled
else
DISPLAY=:0 gsettings set org.gnome.desktop.background picture-options centered
fi
DISPLAY=:0 gsettings set org.gnome.desktop.background picture-uri "file:$wallpaperImage"
DISPLAY=:0 gsettings set org.gnome.desktop.background primary-color "#000000"
DISPLAY=:0 gsettings set org.gnome.desktop.background secondary-color "#000000"
fi
if [[ "$DESKTOP" = "mate14" ]]; then
if [ $wallpaperImage_width -gt $wallpaperWidth -o $wallpaperImage_height -gt $wallpaperHeight ]; then
mateconftool-2 -t string -s /desktop/mate/background/picture_options scaled
else
mateconftool-2 -t string -s /desktop/mate/background/picture_options centered
fi
mateconftool-2 -t string -s /desktop/mate/background/picture_filename "$wallpaperImage"
mateconftool-2 -t string -s /desktop/mate/background/primary_color "#000000"
mateconftool-2 -t string -s /desktop/mate/background/secondary_color "#000000"
fi
if [[ "$DESKTOP" = "mate16" ]]; then
matePID=$(pgrep mate-session)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$matePID/environ|cut -d= -f2-)
if [ $wallpaperImage_width -gt $wallpaperWidth -o $wallpaperImage_height -gt $wallpaperHeight ]; then
DISPLAY=:0 gsettings set org.mate.background picture-options scaled
else
DISPLAY=:0 gsettings set org.mate.background picture-options centered
fi
DISPLAY=:0 gsettings set org.mate.background picture-filename "$wallpaperImage"
DISPLAY=:0 gsettings set org.mate.background primary-color "#000001"
DISPLAY=:0 gsettings set org.mate.background secondary-color "#000002"
fi
if [[ "$DESKTOP" = "xfce" ]]; then
# image-style: 0=Auto, 1=Centered, 2=Tiled, 3=Stretched, 4=Scaled, 5=Zoomed
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-show -s false
if [ $wallpaperImage_width -gt $wallpaperWidth -o $wallpaperImage_height -gt $wallpaperHeight ]; then
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-style -s 4
else
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-style -s 1
fi
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s "$wallpaperImage"
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-show -s true
fi
【问题讨论】: