Skip to content

Instantly share code, notes, and snippets.

Created April 27, 2012 19:07
Show Gist options
  • Save anonymous/0d6dd227dd983ee80131 to your computer and use it in GitHub Desktop.
Save anonymous/0d6dd227dd983ee80131 to your computer and use it in GitHub Desktop.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance Force
;check background on login
WM_DISPLAYCHANGE(0,0)
OnMessage(0x7E, "WM_DISPLAYCHANGE")
return
WM_DISPLAYCHANGE(wParam, lParam)
{
;WM_DISPLAYCHANGE is triggered any time a change is made to the display settings
;get the monitor count
SysGet, mc, MonitorCount
if mc = 1
{
;if 1 monitor, use this background
source = C:\*folder* ;do not include end forward-slash
filesn =
files =
filetopick =
file =
background_file =
numberoffiles :=
Loop,%source%\*.*,0,0
filesn.= A_LoopFileName . "`n"
StringSplit, files, filesn, `n
;set tile and style accordingly
Sleep, 600
SetWallpaperStyle("Fill")
;set background file
Loop, %source%\*.*, 1, 1
numberoffiles += 1
Random,filetopick,1,numberoffiles
file .= files%filetopick%
background_file = %source%\%file%
DllCall("SystemParametersInfo", UInt, 0x14, UInt, 0, Str, background_file, UInt, 2)
SetTimer, Reset, 600000 ;reload every 10 minutes after new background is set
}
else if mc = 2
{
;if 2 monitors, use this background
source = C:\*folder* ;do not include end forward-slash
filesn =
files =
filetopick =
file =
background_file =
numberoffiles :=
Loop,%source%\*.*,0,0
filesn.= A_LoopFileName . "`n"
StringSplit, files, filesn, `n
;set tile and style accordingly
Sleep, 600
SetWallpaperStyle("Tiled")
;set background file
Loop, %source%\*.*, 1, 1
numberoffiles += 1
Random,filetopick,1,numberoffiles
file .= files%filetopick%
background_file = %source%\%file%
DllCall("SystemParametersInfo", UInt, 0x14, UInt, 0, Str, background_file, UInt, 2)
SetTimer, Reset, 600000 ;reload every 10 minutes after new background is set
}
}
#3::Reload
Reset:
{
Reload
}
SetWallpaperStyle(style)
{
;for tiled, use TileWallpaper=1 WallpaperStyle=0
;for centered, use TileWallpaper=0 WallpaperStyle=0
;for strech, use TileWallpaper=0 WallpaperStyle=2
;for fit, use TileWallpaper=0 WallpaperStyle=6
;for fill, use TileWallpaper=0 WallpaperStyle=10
if style=Tiled
{
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, TileWallpaper, 1
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, WallpaperStyle, 0
}
else if style=Centered
{
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, TileWallpaper, 0
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, WallpaperStyle, 0
}
else if style=Streched
{
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, TileWallpaper, 0
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, WallpaperStyle, 2
}
else if style=Fit
{
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, TileWallpaper, 0
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, WallpaperStyle, 6
}
else if style=Fill
{
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, TileWallpaper, 0
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, WallpaperStyle, 10
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment