我在Linux Mint中有一个墙纸更换脚本,如下所示(在crontab *中运行)。如果您对其进行分析,则意味着如果随机图片的高度或宽度大于屏幕宽度,则按比例缩放它,否则就不缩放而只是将其居中(这里有条件)。
它工作得很好,我喜欢我的剧本。但是,我在Windows中找不到类似的东西,我想知道是否有人在附近有一个像这样的脚本,而不是我必须编写它?
windows墙纸的问题在于,没有选项不将图片缩放到您的宽度/高度屏幕以下,并且同时将图片缩放到您的宽度/高度以下。在Linux中是同样的问题,但这就是为什么我为此编写了脚本。
请不要回答我是否需要调整图像大小。我不需要我在Linux中找到了解决方案,当然可以在Windows中自动完成。只需将要用于Task Scheduler的VBS或PowerShell脚本即可。
* Crontab笔记可更改200万张墙纸:
*/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
答案 0 :(得分:0)
不幸的是,我不得不编写整个代码。效果很好,但在极少数情况下,Fit和Center混合在一起了。
wallpaper-changer.vbs
Dim shell,command
command = "powershell.exe -nologo -command ""C:\Scripts\wallpaper-changer.ps1"""
Set shell = CreateObject("WScript.Shell")
shell.Run command,0
wallpaper-changer.ps1
# https://gist.github.com/ivandeex/43477bdecb9ebd4e86fc328f81485e4f
# Installation
# Add C:\Scripts\wallpaper-changer.vbs
# Add C:\Scripts\wallpaper-changer.ps1
# Run in command line:
# schtasks /Create /TN "wallpaper-changer" /SC MINUTE /MO 2 /TR "C:\Scripts\wallpaper-changer.vbs"
# /MO 2 = change every 2 minutes
$wallPaperFolder = 'C:\your-picture-folder'
Function Update-Wallpaper {
Param(
[Parameter(Mandatory=$true)]
$Path,
[ValidateSet('Center','Stretch','Fill','Tile','Fit')]
$Style
)
Try {
if (-not ([System.Management.Automation.PSTypeName]'Wallpaper.Setter').Type) {
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace Wallpaper {
public enum Style : int {
Center, Stretch, Fill, Fit, Tile
}
public class Setter {
public const int SetDesktopWallpaper = 20;
public const int UpdateIniFile = 0x01;
public const int SendWinIniChange = 0x02;
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni);
public static void SetWallpaper ( string path, Wallpaper.Style style ) {
SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange );
RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
switch( style ) {
case Style.Tile :
key.SetValue(@"WallpaperStyle", "0") ;
key.SetValue(@"TileWallpaper", "1") ;
break;
case Style.Center :
key.SetValue(@"WallpaperStyle", "0") ;
key.SetValue(@"TileWallpaper", "0") ;
break;
case Style.Stretch :
key.SetValue(@"WallpaperStyle", "2") ;
key.SetValue(@"TileWallpaper", "0") ;
break;
case Style.Fill :
key.SetValue(@"WallpaperStyle", "10") ;
key.SetValue(@"TileWallpaper", "0") ;
break;
case Style.Fit :
key.SetValue(@"WallpaperStyle", "6") ;
key.SetValue(@"TileWallpaper", "0") ;
break;
}
key.Close();
}
}
}
"@ -ErrorAction Stop
}
}
Catch {
Write-Warning -Message "Wallpaper not changed because $($_.Exception.Message)"
}
[Wallpaper.Setter]::SetWallpaper( $Path, $Style )
}
# Get a random image file
$wallpaperRandom = Get-ChildItem -Path "$wallpaperFolder" -Recurse | Select-Object FullName | Get-Random -Count 1
# Get the width/height of the file
$wallpaperDetails = New-Object -ComObject Wia.ImageFile
$wallpaperDetails.loadfile($wallpaperRandom.FullName)
# Get screen resolution
Add-Type -AssemblyName System.Windows.Forms
# Set wallpaper
If ( $wallpaperDetails.Width -gt [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Width -Or $wallpaperDetails.Height -gt [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Height ) {
Update-Wallpaper -Path $wallpaperRandom.FullName -Style Fit
}
Else {
Update-Wallpaper -Path $wallpaperRandom.FullName -Style Center
}