Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Wallpaper Changer


  • Please log in to reply
24 replies to this topic
aCkRiTe
  • Members
  • 577 posts
  • Last active: Jun 21 2013 11:01 PM
  • Joined: 21 Jul 2006
Here is a Wallpaper Changer script that I created. The script requires IrfanView if ALL the images in the selected folder are not bitmap (.bmp) images. Though the script will detect if IrfanView is not installed and GIVE YOU THE OPTION to download it. Hell I had fun just uninstalling and reinstalling IrfanView withf this script! :lol: By the way I left line 196 like this *;Interval = 5000*, just for testing purposes. If you want you can use this to test at your own image interval rate. That is if it’s not between 1 minute and 1 hour. The script also creates a directory "C:\Documents and Settings\%A_UserName%\Wallpaper Changer" to use for the script. I have tested over and over, but if there are any errors or if there is something I missed, please let me know. Thanks....

Posted Image

Posted Image


#SingleInstance Force 
#Persistent 
#NoEnv 
SetBatchLines, -1 
OnExit, Exit_Label 
Gosub, TrayMenu 
Img_Order = Fixed 
Wallpaper_Changer_Dir = C:\Documents and Settings\%A_UserName%\Wallpaper Changer 
IfNotExist, %Wallpaper_Changer_Dir% 
	FileCreateDir, %Wallpaper_Changer_Dir% 
RegRead, Original_Wallpaper, HKEY_CURRENT_USER, Control Panel\Desktop, Wallpaper
RegRead, Original_TileWallpaper, HKEY_CURRENT_USER, Control Panel\Desktop, TileWallpaper 
RegRead, Original_WallpaperStyle, HKEY_CURRENT_USER, Control Panel\Desktop, WallpaperStyle 
Wallpaper_Changer: 
FileDelete, C:\Documents and Settings\%A_UserName%\Local Settings\Temp\Wallpaper.tmp 
SetTimer, Subroutine 
Gui, Destroy    
Gui, Font, s11 
Gui, Add, GroupBox, x5 y5 w280 h50, Folder With Images 
Gui, Add, GroupBox, x5 y60 w348 h65, Image Interval 
Gui, Add, GroupBox, x5 y130 w185 h48, Image Position 
Gui, Add, GroupBox, x200 y130 w153 h48, Image Order 
Gui, Add, Edit, x10 y25 w270 h20 ReadOnly 
Gui, Add, Button, x290 y12 w65 h25, Browse 
Gui, Add, Slider, x10 y80 w337 h30 gSubroutine AltSubmit Range1-60 ToolTip NoTicks Page1 Line1, 30 
Gui, Add, Radio, x12 y150 w60 h20 vRadio1 Checked, Center 
Gui, Add, Radio, x78 y150 w60 h20 vRadio2, Stretch 
Gui, Add, Radio, x144 y150 w40 h20 vRadio3, Tile 
Gui, Add, Radio, x210 y150 w75 h20 vRadio4 Group Checked, Random 
Gui, Add, Radio, x293 y150 w50 h20 vRadio5, Fixed 
Gui, Font, s8 
Gui, Add, Text, x20 y110, 1 Min 
Gui, Add, Text, x160 y110, 30 Min 
Gui, Add, Text, x305 y110, 60 Min 
Gui, Font, s12 Bold 
Gui, Add, Button, x5 y182 w350 h30, Apply 
GuiControl, Disable, Apply 
Gui, Show, h215 w360 Center, Wallpaper Changer 
Return 

Subroutine: 
GuiControlGet, Interval, , msctls_trackbar321 
IfWinActive, Wallpaper Changer 
   	ToolTip, %Interval% Min, 303, 75 
IfWinNotActive, Wallpaper Changer 
   	ToolTip 
Return 

Scanning_Images: 
ToolTip, Scanning Images`nPlease Wait........, , , 2 
Return 

OnMessage(0x53, "WM_HELP") 
WM_HELP(wParam, lParam) 
{ 
   	Run, iexplore.exe http://www.IrfanView.com, Max 
   	If ErrorLevel = Error 
      		MsgBox, 8208, ERROR, Unable to load http`://www.IrfanView.com 
   	Return 
} 

ButtonBrowse: 
Gui, +OwnDialogs 
GuiControl, Disable, Apply 
FileSelectFolder, Folder, *%A_MyDocuments%\My Pictures, 0, `r 
If Folder = 
   	{ 
      		MsgBox, 8208, ERROR, No folder has been selected 
      		Return 
   	} 
SetTimer, Scanning_Images 
GuiControl, , Edit1, %Folder% 
FileDelete, %Wallpaper_Changer_Dir%\*.*    
Total_Img_Cnt = 0 
Loop, %Folder%\*.* 
   	{ 
      		If A_LoopFileExt in bmp,dib,gif,png,jpg,jpeg,jpe,jfif,tif,tiff 
         		Total_Img_Cnt := Total_Img_Cnt + 1 
   	} 
Total_Bmp_Cnt = 0 
Loop, %Folder%\*.bmp 
   	Total_Bmp_Cnt = %A_Index% 
If Total_Img_Cnt = %Total_Bmp_Cnt% 
   	{ 
      		Loop, %Folder%\*.bmp 
         		FileCopy, %A_LoopFileFullPath%, %Wallpaper_Changer_Dir%\%A_Index%.bmp 
   	} 
Else 
   	{ 
      		SetTimer, Scanning_Images, Off 
      		ToolTip, , , , 2 
      		RegRead, IrfanView, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\IrfanView, UninstallString 
      		SplitPath, IrfanView, , IrfanView 
      		IrfanView = %IrfanView%\i_view32.exe 
      		IfNotExist, %IrfanView% 
         		{ 
            			MsgBox, 16452, IrfanView, 
            			(LTrim 
            			All the images in "%Folder%" are not bitmap (.bmp) images. 
            			IrfanView is required if all the images are not bitmap (.bmp) images.`n 
            			Select the 'Help' button to read about IrfanView. 
            			If you select the 'Yes' button, you will download IrfanView (Version 4.0).
            			If you select not to download IrfanView, just select another folder that contains ALL (.bmp) images.`n`n 
            			Would you like to download IrfanView now? 
            			) 
         		} 
      		IfMsgBox, Yes 
         		{ 
            			Run, iexplore.exe https://ahknet.autohotkey.com/~ackrite/iview400_setup.exe, , Hide       
            			WinMinimizeAll 
            			Loop, 300000 
               				{	 
                  				Sleep, 1000 
                  				RegRead, IrfanView, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\IrfanView, UninstallString 
                 				SplitPath, IrfanView, , IrfanView 
                  				IrfanView = %IrfanView%\i_view32.exe 
                  				IfExist, %IrfanView% 
                     					Loop, 300000 
                        					{ 
                           						Sleep, 1000 
                           						IfWinNotExist, IrfanView Setup 
                              							{ 
                                 							WinActivate, Wallpaper Changer 
                                 							MsgBox, 64, IrfanView, Download Complete! 
                                 							Gui, Show, h215 w360 Center, Wallpaper Changer
											WinActivate, Wallpaper Changer
											Goto, IrfanView 
                              							} 
                        					} 
					} 
				IfNotExist, %IrfanView% 
  					ExitApp 
         		} 
      		IfMsgBox, No 
         		{ 
            			GuiControl, , Edit1 
            			Goto, ButtonBrowse 
         		} 
      		IrfanView: 
      		GuiControl, , Edit1, %Folder% 
      		SetTimer, Scanning_Images 
      		Total_Img_Cnt = 0 
      		Loop, %Folder%\*.* 
         		{ 
            			If A_LoopFileExt in bmp,dib,gif,png,jpg,jpeg,jpe,jfif,tif,tiff 
               				{ 
                  				Total_Img_Cnt := Total_Img_Cnt + 1 
                  				RunWait, "%IrfanView%" "%A_LoopFileFullPath%" /convert="%Wallpaper_Changer_Dir%\%Total_Img_Cnt%.bmp" 
               				} 
         		} 
   	} 
SetTimer, Scanning_Images, Off 
ToolTip, , , , 2 
If Total_Img_Cnt <= 1 
   	{ 
      		MsgBox, 8208, ERROR, There is only one or no image files in "%Folder%".`n`nCheck the folder and try again or select a differnt folder. 
      		GuiControl, , Edit1 
      		Return 
   	} 
GuiControl, Enable, Apply 
Return 

ButtonApply: 
Gui, Submit, NoHide 
Menu, Tray, Enable, Set to Original Wallpaper 
Menu, Tray, Enable, Set to Current Wallpaper
FileDelete, C:\Documents and Settings\%A_UserName%\Local Settings\Temp\Wallpaper.tmp 
If Radio1 = 1 
   	{ 
      		Position = Center
      		TileWallpaper = 0 
      		WallpaperStyle = 0 
   	} 
If Radio2 = 1 
   	{ 
      		Position = Stretch
      		TileWallpaper = 0 
      		WallpaperStyle = 2 
   	} 
If Radio3 = 1 
   	{ 
      		Position = Tile
      		TileWallpaper = 1 
      		WallpaperStyle = 0    
   	} 
Img_Order = Random 
If Radio4 = 1 
   	Img_Order = Random 
If Radio5 = 1 
   	{ 
      		Img_Order = Fixed 
      		Img_Cnt = 1 
   	} 
IniWrite, %Folder%, %Wallpaper_Changer_Dir%\Wallpaper.ini, Wallpaper Changer Settings, Path
IniWrite, %Interval%, %Wallpaper_Changer_Dir%\Wallpaper.ini, Wallpaper Changer Settings, Interval
IniWrite, %Position%, %Wallpaper_Changer_Dir%\Wallpaper.ini, Wallpaper Changer Settings, Position
IniWrite, %Img_Order%, %Wallpaper_Changer_Dir%\Wallpaper.ini, Wallpaper Changer Settings, Order
SetTimer, Subroutine, Off 
ToolTip 
Gui, Submit 
Previous_Settings:
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, TileWallpaper, %TileWallpaper% 
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, WallpaperStyle, %WallpaperStyle%
Menu, Tray, Disable, Hide 
Menu, Tray, Enable, Show 
Interval *= 60000 
;Interval = 3000 
SetTimer, %Img_Order%, %Interval% 
GoSub, %Img_Order% 
Return 

Random: 
Random, Img, 1, %Total_Img_Cnt% 
Img = %Img%.bmp 
GoSub, Show_Img 
Return 

Fixed: 
Loop, %Wallpaper_Changer_Dir%\*.bmp 
   	{ 
      		If (Img_Cnt = Total_Img_Cnt + 1) 
         		Img_Cnt = 1 
      		If A_Index = %Img_Cnt% 
         		{ 
            			Img = %A_LoopFileName% 
            			Img_Cnt := Img_Cnt + 1 
            			Break 
         		} 
   	} 
GoSub, Show_Img 
Return 

Show_Img: 
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, Wallpaper, %Wallpaper_Changer_Dir%\%Img% 
Run, %A_WinDir%\System32\RUNDLL32.EXE user32.dll`,UpdatePerUserSystemParameters 
Return 

TrayMenu: 
Menu, Tray, MainWindow 
Menu, Tray, NoStandard 
Menu, Tray, Add, Wallpaper Changer, Wallpaper_Changer
Menu, Tray, Add 
Menu, Tray, Add, View Previous Settings, View_Previous_Settings
Menu, Tray, Add, Set to Previous Settings, Set_to_Previous_Settings
Menu, Tray, Add, Set to Original Wallpaper, Set_to_Original_Wallpaper 
Menu, Tray, Add, Set to Current Wallpaper, Set_to_Current_Wallpaper 
Menu, Tray, Add, Hide, Hide 
Menu, Tray, Add, Show, Show 
Menu, Tray, Add, Exit, GuiClose 
Menu, Tray, Disable, Set to Original Wallpaper 
Menu, Tray, Disable, Set to Current Wallpaper 
Menu, Tray, Default, Wallpaper Changer 
Menu, Tray, Disable, Show 
Return 

Hide: 
WinHide, Wallpaper Changer 
Menu, Tray, ToggleEnable, Hide 
Menu, Tray, ToggleEnable, Show 
Return 

Show: 
Gui, Show, h215 w360 Center, Wallpaper Changer 
WinActivate, Wallpaper Changer 
Menu, Tray, ToggleEnable, Show 
Menu, Tray, ToggleEnable, Hide 
Return

View_Previous_Settings:
IniRead, Folder, %Wallpaper_Changer_Dir%\Wallpaper.ini, Wallpaper Changer Settings, Path
IniRead, Interval, %Wallpaper_Changer_Dir%\Wallpaper.ini, Wallpaper Changer Settings, Interval
IniRead, Position, %Wallpaper_Changer_Dir%\Wallpaper.ini, Wallpaper Changer Settings, Position
IniRead, Order, %Wallpaper_Changer_Dir%\Wallpaper.ini, Wallpaper Changer Settings, Order
MsgBox, 64, Wallpaper Changer Settings, Path = %Folder%`nInterval = %Interval%`nPosition = %Position%`nOrder = %Order%
Return

Set_to_Previous_Settings:
IniRead, Folder, %Wallpaper_Changer_Dir%\Wallpaper.ini, Wallpaper Changer Settings, Path
IniRead, Interval, %Wallpaper_Changer_Dir%\Wallpaper.ini, Wallpaper Changer Settings, Interval
IniRead, Position, %Wallpaper_Changer_Dir%\Wallpaper.ini, Wallpaper Changer Settings, Position
IniRead, Img_Order, %Wallpaper_Changer_Dir%\Wallpaper.ini, Wallpaper Changer Settings, Order
If Img_Order = Fixed
	Img_Cnt = 1
If Position = Center 
   	{ 
      		TileWallpaper = 0 
      		WallpaperStyle = 0 
   	} 
If Position = Stretch 
   	{ 
      		TileWallpaper = 0 
      		WallpaperStyle = 2 
   	} 
If Position = Tile 
   	{ 
      		TileWallpaper = 1 
      		WallpaperStyle = 0    
   	} 
Loop, %Wallpaper_Changer_Dir%\*.bmp
	Total_Img_Cnt = %A_Index%
WinHide, Wallpaper Changer
Goto, Previous_Settings

Set_to_Original_Wallpaper: 
SetTimer, %Img_Order%, Off 
FileAppend, , C:\Documents and Settings\%A_UserName%\Local Settings\Temp\Wallpaper.tmp 
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, Wallpaper, %Original_Wallpaper% 
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, TileWallpaper, %Original_TileWallpaper% 
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, WallpaperStyle, %Original_WallpaperStyle% 
Run, %A_WinDir%\System32\RUNDLL32.EXE user32.dll`,UpdatePerUserSystemParameters 
Menu, Tray, Disable, Set to Original Wallpaper 
Menu, Tray, Disable, Set to Current Wallpaper 
Return 

Set_to_Current_Wallpaper: 
SetTimer, %Img_Order%, Off 
Menu, Tray, Disable, Set to Current Wallpaper 
Return 

GuiClose: 
Exit_Label: 
IfExist, C:\Documents and Settings\%A_UserName%\Local Settings\Temp\Wallpaper.tmp 
   	Goto, Skip 
FileCopy,  %Wallpaper_Changer_Dir%\%Img%, C:\Documents and Settings\%A_UserName%\Local Settings\Application Data\Microsoft\Wallpaper1.bmp, 1 
Skip: 
Run, %A_WinDir%\System32\RUNDLL32.EXE user32.dll`,UpdatePerUserSystemParameters 
ExitApp


slomz
  • Members
  • 601 posts
  • Last active: Mar 30 2008 12:54 AM
  • Joined: 03 Sep 2006
Very nice. Works well.

Alex
  • Guests
  • Last active:
  • Joined: --
Nice script. :)

I've made a choose random sounds/wallpaper script for myself, but my code is too much of a mess to post. Perhaps you're interested in two modifications to enhance your script?

To search for an installation of IrfanView I used
RegRead,IrfanView,HKEY_LOCAL_MACHINE,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\IrfanView,UninstallString
SplitPath,IrfanView,,IrfanView
IrfanView = %IrfanView%\i_view32.exe
And to set the wallpaper, I used following parameter for IrfanView (so it'll fit to the desktop, kinda like Webshots-like). Could be an additional option in your GUI.

RunWait,%IrfanView% "%outputpath%\%outputfile%" /resample=(%A_ScreenWidth%,%A_ScreenHeight%) /aspectratio /wall=0 /killmesoftly
Best regards,

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
It seems that you use IrfanView only for image conversion.
Just for the record, you can do that now using GDI+... Nothing to install (at least on XP!).
But well, everybody has IrfanView installed, no? (or should have... :-))
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

aCkRiTe
  • Members
  • 577 posts
  • Last active: Jun 21 2013 11:01 PM
  • Joined: 21 Jul 2006
@Alex
Thanks for the advice for the “search for installation of IrfanView”, that never even crossed my mind and it’s perfect! And the other parameter for IrfanView I will have to look into and will update the script when I get a chance. Thanks for the input…

@PhiLho
That’s what I intended on at first, no installs or 3rd parties. I did my researching and came across the GDI+…. I just could not understand any of it! :? :( :shock: I’m just not at that level yet, I wish I was. So I knew it was possible, I just couldn’t put it all together… Sorry...:oops:

aCkRiTe
  • Members
  • 577 posts
  • Last active: Jun 21 2013 11:01 PM
  • Joined: 21 Jul 2006
Made a few changes to the script as Alex suggested and also fixed a little problem with the 'set to original wallpaper' option that I found (I hope) :p

oceanclub
  • Guests
  • Last active:
  • Joined: --
I installed IrfanView to my D: drive, and yet the script seems to think it's on C: - any idea why?

Error: Failed attempt to launch program or document
Action: <"C:\Program Files\Irfanview\j_view32.exe">

etc.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
The code checks if IrfanView is indeed installed by looking at its path in registry, then hard-code the call path:
RunWait, "%A_ProgramFiles%\IrfanView\i_view32.exe"
Probably an overview of the developer.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

aCkRiTe
  • Members
  • 577 posts
  • Last active: Jun 21 2013 11:01 PM
  • Joined: 21 Jul 2006
As PhiLho said...

The code checks if IrfanView is indeed installed by looking at its path in registry, then hard-code the call path:
RunWait, "%A_ProgramFiles%\IrfanView\i_view32.exe"
Probably an overview of the developer.


This problem has been fixed and the original post has been edited...

oceanclub
  • Guests
  • Last active:
  • Joined: --
Very neat script. Here's a question though; everytime I reboot, I'm prompted to reconfigure all the settings, such as folder, image interval. etc. Is there a way of setting these in the file so I don't have to - that everytime a reboot happens, the directory is simply scanned for new images?

P.

aCkRiTe
  • Members
  • 577 posts
  • Last active: Jun 21 2013 11:01 PM
  • Joined: 21 Jul 2006

Very neat script. Here's a question though; everytime I reboot, I'm prompted to reconfigure all the settings, such as folder, image interval. etc. Is there a way of setting these in the file so I don't have to - that everytime a reboot happens, the directory is simply scanned for new images?

P.


The script has been updated with your request.. :D I have posted a new screenshot of the tray icon menu as well. If you notice any problems please post back. Enjoy :p

SomeWhiteGuy
  • Guests
  • Last active:
  • Joined: --
This is a great script thank you. I was about to start designing my own when I stumbled upon this script. :D

degarb
  • Members
  • 315 posts
  • Last active: May 03 2015 07:35 PM
  • Joined: 14 Feb 2007
What is latest changer script?

Can you get it to recursively scan and use sub dirs?

degarb
  • Members
  • 315 posts
  • Last active: May 03 2015 07:35 PM
  • Joined: 14 Feb 2007

What is latest changer script?

Can you get it to recursively scan and use sub dirs?


also, doesn't remember directory.

Chucking out of startup menu. No reply. Doubt if I can fix source myself in under a few hours: not worth it.

However, I would any code that works like this script, except remembers settings each boot. Recursive would be nice, but not as essential.

aCkRiTe
  • Members
  • 577 posts
  • Last active: Jun 21 2013 11:01 PM
  • Joined: 21 Jul 2006
Its been a while since I wrote this, but I think changing

Loop, %Folder%\*.* 

to

Loop, %Folder%\*.* , 1, 1

is what your looking for. I dont have time at the moment to look at this, but Im willing to help you out when I get the chance/time.

HTH...