AutoHotkey Community

It is currently May 26th, 2012, 8:37 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: August 24th, 2009, 2:01 pm 
Offline

Joined: August 14th, 2009, 2:40 pm
Posts: 237
Location: Finland
A script made by ashef which I got from here and then edited to it's current form:
Code:
#SingleInstance Force
#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.
IniRead, WallPaperFolder, %A_ScriptDir%\wpchange.ini, Settings, WPFolder, NOT_SET

If WallPaperFolder = NOT_SET
{
   FileSelectFolder, SetFolder, , 3
   if SetFolder =
   {
      MsgBox, You didn't select a folder, the program will now close.   
      ExitApp
   }
   else
   {
      SetFolder := RegExReplace(SetFolder, "\\$")  ; Removes the trailing backslash, if present.   
      WallPaperFolder = %SetFolder%\
      IniWrite, %WallPaperFolder%, %A_ScriptDir%\wpchange.ini, Settings, WPFolder
      MsgBox Setting saved, to reset choose the "Reset Folder" item from tray, or delete file %A_ScriptDir%\wpchange.ini.
   }
}   

RefreshWPs() ; Make a function of it and call that whenever you need to cut down redundant writing.
{
   Global
   ArrayCount=0
   Loop, D:\Stuff\Images\Walls\*.jpg ; wherever you store your wallpapers
   {
   ArrayCount+=1
   Array%ArrayCount% := A_LoopFileName
   }
}

ChangeWP() ; Make a function of it
{
   global
   Random, filenum, 1, %ArrayCount%
   filecalled := Array%filenum%
   TrayTip,, Setting "%filecalled%" as your wallpaper,,1
   FileCopy, %WallPaperFolder%%filecalled%, %A_MyDocuments%\currentwallpaper.jpg, 1
   DllCall("SystemParametersInfo", UInt, 0x14, UInt, 0, Str, A_MyDocuments . "\currentwallpaper.jpg", UInt, 2)
   RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, WallPaper, %WallPaperFolder%%filecalled%
   Sleep, 500 ; can't change the wallpaper too quickly in succession.
   return   
}   

Traytip, Refreshing..., Refreshing Wallpapers...,,1
RefreshWPs()
TrayTip,, Wallpaper list refreshed!,,1
Menu, TRAY, Add
Menu, TRAY, Add, Refresh Wallpapers, RefreshWallpapers ; Manual refresh
Menu, TRAY, Add, Change Wallpaper, ChangeWallpaper ; Add a menu for it too
Menu, TRAY, Add
Menu, TRAY, Add, Reset Folder, RstFolder ; Add menu for resetting folder
Return ; Ends the auto-execute section

RefreshWallpapers: ; does the same job as the auto-execute
   Traytip, Refreshing..., Refreshing Wallpapers...,,1
   RefreshWPs()
   TrayTip,, Wallpaper list refreshed!,,1
   Return

ChangeWallpaper:
   ChangeWP()
   Return

RstFolder:
   IniWrite, NOT_SET, %A_ScriptDir%\wpchange.ini, Settings, WPFolder
   MsgBox Folder settings reset, please restart app to redefine.
   Return

#MButton::ChangeWP()


The weird thing is, it works perfectly on my computer (running Win7 RC), it reads the list ok and changes wallpaper just fine. read/writes ini ok.

Then, I compiled it (and it still works on my computer, I'm using the compiled one myself.) and gave it to my brother (running Win7 RC). He ran it and it created the ini file just fine. BUT, when he tries to change the wallpaper, nothing happens.

well, when it should display a traytip
Code:
TrayTip,, Setting "%filecalled%" as your wallpaper,,1

I got "Setting "filename" as your wallpaper" and my brother gets "Setting "" as your wallpaper"

My path to the images is "D:\Stuff\Images\Walls" and his is "D:\Kuvat\Muut\Wallpapers". So even the paths are similar (no spaces or funny characters). Only real difference is, I have AHK installed and he doesn't, but I don't think it *should* at least matter.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 2:05 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
Change
Code:
TrayTip,, Wallpaper list refreshed!,,1
;To
TrayTip,, Wallpaper list refreshed! (%ArrayCount% Found),,1

to see if his finds any pictures.

The fastest solution might be to connect with him over something like CrossLoop or VNC to see if you can debug it on his machine.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 2:13 pm 
Offline

Joined: August 14th, 2009, 2:40 pm
Posts: 237
Location: Finland
I don't need VNCs or the like, his computer is like 30cm away from mine :D
I added a "debug button" (listvars) to the script and I'm going to see just that, if it finds any wallpapers.

If it doesn't then I'm f***ed, since I have no idea why it wouldn't find any. :)
But he's busy right now so I can't test it at the moment. Well, busy playing WoW, but try telling him AHK scripting is way more fun than playing wow :P


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 2:14 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
VNC can still be a fun trick...

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 2:15 pm 
Offline

Joined: August 14th, 2009, 2:40 pm
Posts: 237
Location: Finland
HAHA :D Yes, indeed. :P


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 2:49 pm 
Offline

Joined: August 14th, 2009, 2:40 pm
Posts: 237
Location: Finland
Tested there, the script just doesn't find any wallpapers what so ever.

ListVars from mine

Code:
Global Variables (alphabetical)
--------------------------------------------------
0[1 of 3]: 0
;Array1-Array193 the individual wallpapers
ArrayCount[3 of 3]: 193
ErrorLevel[1 of 3]: 0
filecalled[12 of 63]: Car (84).jpg
filenum[2 of 3]: 73
SetFolder[0 of 0]: 
Str[0 of 0]: 
UInt[0 of 0]: 
WallPaperFolder[22 of 63]: D:\Stuff\Images\walls\


His:
Code:
Global Variables (alphabetical)
--------------------------------------------------
0[1 of 3]: 0
ArrayCount[1 of 3]: 0
ErrorLevel[1 of 3]: 0
filecalled[0 of 0]: 
filenum[0 of 0]: 
SetFolder[0 of 0]: 
Str[0 of 0]: 
UInt[0 of 0]: 
WallPaperFolder[25 of 63]: D:\Kuvat\Muut\Wallpapers\


No idea anymore.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 2:51 pm 
Offline

Joined: August 14th, 2009, 2:40 pm
Posts: 237
Location: Finland
ARGH! nevermind, I'm being so stupid I hate to admit it :D :D :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 2:53 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
My guess is that you forgot to turn this line to a variable reference?
Code:
Loop, D:\Stuff\Images\Walls\*.jpg ; wherever you store your wallpapers

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 3:02 pm 
Offline

Joined: August 14th, 2009, 2:40 pm
Posts: 237
Location: Finland
Yes, you're right :D oh geez, I feel stupid.

But, there's a slight problem yet again... Now it seemingly works ok. It finds 85 pictures, lists them ok (ListVars), sets the reg key correctly (when I check what wallpaper is currently selected in Personalize.) But it just doesn't really change the wallpaper. I guess the FileCopy isn't doing it's just, but running the compiled script as admin didn't change anything.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 3:04 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
Is the jpg being replaced?

If you delete the jpg, can the script rewrite it?

A_IsAdmin is 1?

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 3:11 pm 
Offline

Joined: August 14th, 2009, 2:40 pm
Posts: 237
Location: Finland
A_IsAdmin is 1 yes.
But, the currentwallpaper.jpg file isn't being created in the first place. And I don't get it why?

After stupid variable corrections and typo fixes, here's the current version of the script:
Code:
#SingleInstance Force
#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.
IniRead, WallPaperFolder, %A_ScriptDir%\wpchange.ini, Settings, WPFolder, NOT_SET

If WallPaperFolder = NOT_SET
{
   FileSelectFolder, SetFolder, , 3
   if SetFolder =
   {
      MsgBox, You didn't select a folder, the program will now close.   
      ExitApp
   }
   else
   {
      SetFolder := RegExReplace(SetFolder, "\\$")  ; Removes the trailing backslash, if present.   
      WallPaperFolder = %SetFolder%\
      IniWrite, %WallPaperFolder%, %A_ScriptDir%\wpchange.ini, Settings, WPFolder
      MsgBox Setting saved. To reset, choose the "Reset Folder" item from tray or delete file %A_ScriptDir%\wpchange.ini.`n`nYou can now change your wallpaper at will by pressing "Win+MiddleMouseButton". The program will select a random image from the folder you provided and set it as your wallpaper.
   }
}   

RefreshWPs() ; Make a function of it and call that whenever you need to cut down redundant writing.
{
   Global
   ArrayCount=0
   Loop, %WallPaperFolder%*.jpg ; wherever you store your wallpapers
   {
   ArrayCount+=1
   Array%ArrayCount% := A_LoopFileName
   }
}

ChangeWP() ; Make a function of it
{
   global
   Random, filenum, 1, %ArrayCount%
   filecalled := Array%filenum%
   TrayTip,, Setting "%filecalled%" as your wallpaper,,1
   FileCopy, %WallPaperFolder%%filecalled%, %A_MyDocuments%\currentwallpaper.jpg, 1
   DllCall("SystemParametersInfo", UInt, 0x14, UInt, 0, Str, A_MyDocuments . "\currentwallpaper.jpg", UInt, 2)
   RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, WallPaper, %WallPaperFolder%%filecalled%
   Sleep, 500 ; can't change the wallpaper too quickly in succession.
   return   
}   

Traytip, Refreshing..., Refreshing Wallpapers...,,1
RefreshWPs()
TrayTip,, Wallpaper list refreshed! (%ArrayCount% Found),,1
Menu, TRAY, Add
Menu, TRAY, Add, Refresh Wallpapers, RefreshWallpapers ; Manual refresh
Menu, TRAY, Add, Change Wallpaper, ChangeWallpaper ; Add a menu for it too
Menu, TRAY, Add
Menu, TRAY, Add, Reset Folder, RstFolder ; Add menu for resetting folder
Return ; Ends the auto-execute section

RefreshWallpapers: ; does the same job as the auto-execute
   Traytip, Refreshing..., Refreshing Wallpapers...,,1
   RefreshWPs()
   TrayTip,, Wallpaper list refreshed! (%ArrayCount% Found),,1
   Return

ChangeWallpaper:
   ChangeWP()
   Return

RstFolder:
   IniWrite, NOT_SET, %A_ScriptDir%\wpchange.ini, Settings, WPFolder
   MsgBox, 52, Wallpaper Changer, Folder settings reset to defaults. To choose a new folder`, the program must be restarted. Do you want to close the application now?
   IfMsgBox Yes
      ExitApp
   Return

#MButton::ChangeWP()
^!Numpad0::MsgBox %A_IsAdmin%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 3:14 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
try setting to a different wallpaper then back to the jpg, and see if it sticks.

Refresh the desktop with F5?

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 3:25 pm 
Offline

Joined: August 14th, 2009, 2:40 pm
Posts: 237
Location: Finland
The thing is, the FileCopy line doesn't create the jpg at all. the currentwallpaper.jpg file is nowhere to be found at any time. I checked the A_MyDocuments variable if Win7's default path is some curious path, but its just a normal "C.\Users\username\Documents" and his username is just one word, no spaces. So its a perfectly legal path from any angle.

As the DllCall line sets the wallpaper ok (you can see the new wallpaper if you right-click desktop, choose personalize and check the lower part of the appearing window - this in Win7). It's just that the FileCopy apparently fails, and I have no idea why. It's running as admin (and it's the user's own documents folder in the first place), so I really don't think it's a case of limited permissions.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 3:27 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
ErrorLevel?

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 3:34 pm 
Offline

Joined: August 14th, 2009, 2:40 pm
Posts: 237
Location: Finland
Yep, FileCopy returns ErrorLevel 1, so it apparently is that what fails. But why? Why can't it copy the file?

EDIT: the documents folder in question has Full Access for SYSTEM, Administrators-group and the Owner in question (user).


Last edited by AnttiV on August 24th, 2009, 3:39 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, joetazz, Leef_me, Mickers, tidbit, tomoe_uehara and 56 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