3

My question is, can you detect if desktop is currently visible in batch scripting(For Vista)?

The Idea is this: I'm writing a script as a prank for my friend. Some of you may heard about Weeping Angels from Doctor Who. I'm trying to make the script so that each time you return to desktop(Like minimizing something you were looking at), wallpaper changes to another image of the angel, creating the illusion that it's moving when you aren't looking, just like in the series.

My idea for this was to detect when the desktop is not visible, and each time it became visible again, the wallpaper would cycle to the next image. Problem is, I have no idea about how to do that.

Aside from the actual question, any tips regarding the effect is appreciated.

Thank you.

2 Answers2

1

Well, this isn't exactly what you asked for (not sure it is possible to detect the active window)... but it has some of the pieces you were looking for.

Basically it will change your wallpaper to one of several you have in a folder every x less than 5 minutes, where x is a random number. let me know if you have any ideas on how to change it/suggestions/questions.

@echo off 
rem random number of milliseconds (0-5 minutes)
SET /A time=%RANDOM% * (300000 / 32768)
echo waiting %time% ms
PING 1.1.1.1 -n 1 -w %TIME% >NUL
echo done

rem index between 1 and 5
SET /A WALL_INDEX = %random% %% 5 + 1
rem create a folder with many wallpapers in it, and name them 1.png, 2.png, 3.png ... x.png
set WALL="C:\%WALL_INDEX%.png"

rem this is how you change the wallpaper, i stole this from some random site, but I tested it and it seemed to work... usually.
@echo off
reg add "hkcu\control panel\desktop" /v wallpaper /t REG_SZ /d "" /f 
rem sets the wallpaper to the path in %WALL%
reg add "hkcu\control panel\desktop" /v wallpaper /t REG_SZ /d %WALL% /f 
reg delete "hkcu\Software\Microsoft\Internet Explorer\Desktop\General" /v WallpaperStyle /f
reg add "hkcu\control panel\desktop" /v WallpaperStyle /t REG_SZ /d 0 /f
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
Gray
  • 7,050
  • 2
  • 29
  • 52
  • 1
    Thanks for your reply but, I have already figured how to do it based on time(In fact, I'm currently testing it on my PC, it's 2:15 AM, and I am scared to death :) ) The main problems are: Changing it based on time is too random and will likely jump frames which make it less frightening.. And also, I too used the code above. It sometimes works, and sometimes it doesn't... Have no idea why. – LuckyHorseCoin Jul 12 '13 at 23:17
1

You can do it using a Java library called Sikuli which does screen pattern matching. All you do is screenshot the desktop the exact way you wish it to appear when it causes the trigger and then set the unit test to run in a 5 second loop, always checking for the desktop to appear a certain way and then trigger the wallpaper change. So, its going to take a mix of Java/JUnit/Sikuli and batch scripting. Also, you would have to get the batch script into their startup programs list somehow.

djangofan
  • 28,471
  • 61
  • 196
  • 289
  • Umm.. First of all thanks for your reply. But, I don't think i will have complete control over his GUI when I schedule the script for startup. Also, as far as I understand with my current level of drowsiness, this couldn't be run invisibly, which kinda kills the prank :). Thanks anyways... – LuckyHorseCoin Jul 12 '13 at 23:22
  • No, this can in-fact be ran invisibly. When you execute java from the batch script, just use javaw.exe and it executes in the background. Also, rather than scheduling it, I think you would have to actually put it in his startup programs list. – djangofan Jul 12 '13 at 23:29
  • Well, that eliminates one of the problems. But again, as far as i understand, if he changes the location of even a single file on his desktop, the script would fail, correct? And yes, I meant adding to startup list by scheduling. Drowsiness... – LuckyHorseCoin Jul 12 '13 at 23:33
  • Sikuli can do percentage-fuzzy matching and so it would work even if they moved icons. – djangofan Nov 01 '13 at 19:39