Sign in to follow this  
Followers 0

Wallpaper randomizer

1 post in this topic


This is a script I wrote to change the desktop wallpaper in Windows, choosing an image file (JPG/GIF/PNG) from a given folder and subfolders. It requires several libraries and external programs:

- Lazycat's get_image_size UDF (attached) to make sure the chosen image is landscape format (i.e. width>height).

- ImageMagick to convert the picture to the correct size BMP, and also add a caption at the bottom showing the picture's filename. I wanted this because I have a lot of digital photos, and I can never remember exactly where I took them!

- IrfanView to set the wallpaper. I've searched on the forums, but I couldn't find a reliable way of doing this natively in AutoIt (refreshing the desktop seems to be the big problem).

If you place a file called 'exclude.txt' in the root image folder, it will NOT choose any image filenames that contain the text on any one of the lines in this file. (Does that make sense?) So if your exclude.txt contains a line that says 'Brian's party', the script will not pick 'E:\pics\Brian's party\001.jpg', 'E:\pics\Brian's party\002.jpg', etc.

You will need to change the folder that it searches in for images, the size it resizes them to (although it uses the 'stretch' option so this isn't critical), and possibly the text size for the caption (this appears twice in the command).

Any comments? I've got this set up to change the wallpaper once daily, and it seems to work quite well.



; Wallpaper randomizer 1.0
; Ben Shepherd queeg500'at'yahoo'dot'com
; 17/6/5

#include <get_image_size.au3>

$piclist = "piclist.txt"

$picfolder = "E:\Pictures\"
FileChangeDir ($picfolder)
RunWait (@ComSpec & " /c dir/s/b *.jpg;*.gif;*.png >" & $piclist, "", @SW_HIDE)

$list = FileRead ($piclist, FileGetSize ($piclist))
If @error = 1 Then
    MsgBox (0, "", "Error reading from " & $piclist)
    Exit 1

$list = StringSplit ($list, @CRLF, 1)
;MsgBox (0, "", $list[1])

$exclude = FileRead ("exclude.txt", FileGetSize ("exclude.txt"))
$exclude = StringSplit ($exclude, @CRLF, 1)
;MsgBox (0, "", $exclude[1])

$ok = 0
While $ok = 0
; pick random image
    $rnd = Random (1, $list[0])
    $picfile = $list[$rnd]
;MsgBox (0, "", "XX" & $picfile & "XX")

; is it in excluded list?
    $ok = 1
    For $i = 1 To $exclude[0]
    ;MsgBox (0, "", $picfile & @CRLF & $exclude [$i])
        If StringInStr ($picfile, $exclude [$i]) Then $ok = 0
    If $ok = 1 Then
    ; check width>height, i.e. is landscape format
        $imgSize = _GetImageSize($picfile)
        If @error = 0 Then
        ;MsgBox (0, "", $imgSize[0] & "x" & $imgSize[1])
            If $imgSize[0] <= $imgSize[1] Then $ok = 0

;MsgBox (0, "", $picfile)
$shortpicfile = StringTrimLeft ($picfile, StringLen ($picfolder))
; replace quotes with backquotes so ImageMagick can parse the command correctly
$shortpicfile = StringReplace ($shortpicfile, "'", "`")
; replace '\ with '\ ' so that ImageMagick doesn't parse escaped \'s
$shortpicfile = StringReplace ($shortpicfile, "\", "\ ")
;MsgBox (0, "", $shortpicfile)

$command = '"c:\Program Files\ImageMagick\convert.exe" "' & $picfile & '" -resize 1600x1200 -gravity SouthWest -pointsize 30 -stroke #FFFFFF -fill #FFFFFF -draw "text 20,20 ' & "'" & $shortpicfile & "'" & '" -stroke #000000 -fill #000000 -draw "text 21,21 ' & "'" & $shortpicfile & "'" & '" E:\wallpaper.bmp'
;MsgBox (0, "", $command)
;ClipPut ($command)
RunWait ($command, "", @SW_HIDE)
RunWait ('"c:\program files\irfanview\i_view32.exe" E:\wallpaper.bmp /wall=2 /killmesoftly', "", @SW_HIDE)


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0