I came here to find some suggestions on how to change my wallpaper with AHK, and find this wonderful script already written. Thanks!
I made one tweak to the script to make it slightly faster. Especially for people with a very large number of wallpaper images on their system. The randomizer you used depended on two arrays, a temporary array for the file names, and a final array that you moved the names into for randomizing. Every time you took a name from the temporary array, you had to reset a portion of the file names. In the worst case this ends up taking N-squared/2 moves. Meaning with a thousand images you could make millions of swaps.
With my code we use a single array and randomize it in place, swapping names as we go through the list once. The final result should be just as random, but take much less time.
Code:
ScanFiles:
Loop %ImageDir%\*.*,0,1
{
SplitPath A_LoopFileLongPath,,, OutExtension
If( OutExtension <> "bmp" and OutExtension <> "png" and OutExtension <> "jpg" and OutExtension <> "gif" )
continue
Counter++
Image%Counter% := A_LoopFileLongPath
}
Random Seed, 0, 10000000
Random ,,%Seed%
Loop %Counter% {
i := A_Index
Random SelectedImageIndex , 1, %Counter%
if ( i <> SelectedImageIndex )
{
TmpImage := Image%i%
Image%i% := Image%SelectedImageIndex%
Image%SelectedImageIndex% := TmpImage
}
}
Menu, Tray, Tip, %NameString% %VersionString% - %Counter% Wallpapers Loaded
FirstRun := false
Return