AutoHotkey Community

It is currently May 27th, 2012, 12:11 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: December 23rd, 2005, 8:58 pm 
Offline

Joined: December 23rd, 2005, 8:01 pm
Posts: 6
This is my first attempt in an actual script so go easy on me.

I wrote this script because I wanted to have a different background every time I log into my computer. I know it is kind of odd why I went with applying the background via the Windows XP theme, but where I work the computers are re-ghosted every night. So since I like the Windows Classic style I need to apply a saved theme file to make Windows change to classic style.

For my examples the default file locations are setup to drive z:\ (our home directory on the work computers) so that I can store the script and background files there. My original plan was to share this with my co-workers so the default paths are setup that way.

So what you have to do first is create a custom Windows XP theme. Save that with the file name of 'mytheme.Theme'. So before you run the script you should have a directory structure that looks something like this:

z:\profile\background.exe (compiled version)
z:\profile\background.ini (will be created once the script runs)
z:\profile\mytheme.Theme
z:\profile\backgrounds\ - all of the background images you want (can be any image type that Windows allows)
Note: There is no check to make sure that the files in this folder are images. It's mainly because I don't know how to code that while allowing multiple image types.

When you start the script for the first time, it will prompt you for two directory paths: the backgrounds path and the path to mytheme.Theme. You can paste in custom paths if you want to have the files located elsewhere. One issue that I have here is that I don't know how to check that the user put the ending backslash to the path. If they do not provide that the script will error out.

I'm not a natural programmer so the code here might look a bit sloppy and it could probably be done better but it works for me. So this is bascially how the script works, say you have 5 backgrounds in the backgrounds folder. The first time the script runs it will apply the first background, and every time the script runs it will apply the next background. Once you get to the 5th background or the last one the script will see this and start with the first background again.

Code:
;
; Coded by:  Matt Martin
; Last Updated:  12/22/2005
;
SetWorkingDir, %A_WorkingDir%
start:
if FileExist("background.ini")
{
   ; If the ini file exists, this imports all of the variables.
   IniRead, LastTotal, background.ini, info, LastTotal
   IniRead, bgpath, background.ini, info, bgpath
   IniRead, themepath, background.ini, info, themepath
   IniRead, Current, background.ini, info, Current     
}
Else
{
   InputBox, bgpath, Location of the backgrounds, Enter the path to your backgrounds (ie: z:\profile\backgrounds\).  If you press CANCEL it will default to the path below., , 390, 140, , , , , z:\profile\backgrounds\
   if ErrorLevel <> 0
   {
          ; This creates the ini file with default path and values to be called later.
   IniWrite, z:\profile\backgrounds\, background.ini, info, bgpath
   IniWrite, 0, background.ini, info, themepath
   IniWrite, 0, background.ini, info, Current
   IniWrite, 0, background.ini, info, LastTotal
   bgpath = z:\profile\backgrounds\
   }
   else
   {
          ; This creates the ini file with user supplied path and values to be called later.
   IniWrite, %bgpath%, background.ini, info, bgpath
   IniWrite, 0, background.ini, info, themepath
   IniWrite, 0, background.ini, info, Current
   IniWrite, 0, background.ini, info, LastTotal
   bgpath = %bgpath%
   }
   InputBox, themepath, Location of mytheme.Theme, Enter the path to 'mytheme.Theme' (ie: z:\profile\).  If you press CANCEL it will default to the path below., , , 140, , , , , z:\profile\
   if ErrorLevel <> 0
   {
   ; Provides the default path to mytheme.Theme.
   IniWrite, z:\profile\, background.ini, info, themepath
   ;MsgBox, CANCEL was Pressed.  The default theme directory is 'z:\profile\'
   themepath = z:\profile\
   }
   else
   {
   ; Provides the user supplied path to mytheme.Theme
   IniWrite, %themepath%, background.ini, info, themepath
   themepath = %themepath%
   }
}
; This checks to make sure there is a path for the values, if not it will delete the ini file and then prompt the user to try again.
If (bgpath = "" or themepath = "")
{
   FileDelete, background.ini
   MsgBox, 5, , It appears that you did not enter in the directory paths correctly.`n`nRetry?
   IfMsgBox, Retry
   Goto, start
   IfMsgBox, Cancel
   ExitApp
}
; Reads the directory for all image files.
Loop, %bgpath%*.*
{
   ; increments the TotalCount variable every time the loop runs
   TotalCount++
   ; Clears out previous background information
   IniDelete, background.ini, backgrounds, %TotalCount%
   ; writes the current path for all of the files it finds
   IniWrite, %A_LoopFileFullPath%, background.ini, backgrounds, %TotalCount%
}
; Increments the current background variable.
Current++
; Checks to see if the current background in the rotation is higher than the total image count
if (Current > TotalCount)
{
   Current := 1
}
; Writes the current background number to the ini file
IniWrite, %Current%, background.ini, info, Current
; checks to see if The TotalCount is less than LastTotal
; this cleans up any old file paths if backgrounds have been removed since the last time this script ran
if (TotalCount < LastTotal)
{
   ; Finds out how many times this Loop will have to run
   LoopAmount := LastTotal - TotalCount
   Loop, %LoopAmount%
   {
      ; Deletes unused file paths and decreases LastTotal every time the loop runs
      IniDelete, background.ini, backgrounds, %LastTotal%
      LastTotal--
   }
   ; Writes the LastTotal Value to the ini file
   IniWrite, %LastTotal%, background.ini, info, LastTotal
}
; Checks to see if LastTotal is less than TotalCount
; if more backgrounds have been added to the directory this updates the LastTotal value
if (LastTotal < TotalCount)
{
   IniWrite, %TotalCount%, background.ini, info, LastTotal
}
; Reads the file path from the ini file and places it into the variable called myback
IniRead, myback, background.ini, backgrounds, %Current%
; Theme files work just like ini files so I am able to write to the wallpaper line with the ini write command.
iniWrite, %myback%, %themepath%mytheme.theme, Control Panel\Desktop, Wallpaper
; Executes mytheme.theme and applies it
Run, %themepath%\mytheme.Theme
WinWait, Display Properties
IfWinNotActive, Display Properties, , WinActivate, Display Properties,
send a{ENTER}


So there you have it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2006, 11:10 am 
Offline

Joined: December 23rd, 2005, 8:01 pm
Posts: 6
hmm no comments on this yet? oh well.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2007, 4:44 am 
Offline

Joined: October 30th, 2006, 10:17 pm
Posts: 43
Nice just why don't you reverse that to the new theam I have the same problem at school once in a while and while ur at it why not set up a way to change the desktop background?

_________________
Tex© Click here to mail me


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: fincs, Yahoo [Bot] and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group