📜 ⬆️ ⬇️

Art Wallpapers + Weather Widget

Story


It was always interesting to me to know what the weather was like outside the window, in the meantime different weather informers were used and then one day, on the advice of a friend, I came across this site . The site had its own zest, which consisted in the fact that the weather report was displayed on the background of artistic paintings that I wanted to notice of decent quality. All these charms did not leave me indifferent and I added the site to the bookmarks. Time passed, the site moved from the bookmarks to the speed dial tab, which was updated periodically, but something was still missing. And, in the end, I got the idea - to take screenshots of the site and display them on the desktop.

purpose


Implement the idea, while spending as little as possible "resources" for implementation and make it so that the process from the creation of a screenshot to the replacement of wallpaper occurs unnoticed.

Means used

  1. PhantomJS - for getting screenshots from web resources
  2. NConvert - to convert images to various formats
  3. Wallpaper - to update wallpaper in Windows Vista and 7
  4. VBScript - to execute all necessary commands.
  5. Windows Task Scheduler - for regular wallpaper updates

Implementation


First of all, download the latest versions of PhantomJS , NConvert and Wallpaper .
Alas, the archive with the file “wallpaper.exe” is not available, so you can download it from the archive with the source code for the article, the link to which will be published at the end.
At the time of this writing, Windows PhantomJS 1.3.0 (Static build) and NConvert v5.91 were used. Then we create the folder “meteo_wall”, in it we create the subfolder “tools”. Go to this subfolder and unpack the contents of the archive "PhantomJS" in the same folder. Also in the “tools” folder we place NConvert and wallpaper.exe. Next, it will be necessary to copy the “rasterize.js” file from the examples folder and place it in the “tools” folder. We will slightly correct the “rasterize.js” file in order to be able to specify the required screenshots extension.
var page = new WebPage(), address, output, size; if (phantom.args.length < 2 || phantom.args.length > 3) { console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat]'); console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"'); phantom.exit(); } else { address = phantom.args[0]; output = phantom.args[1]; page.viewportSize = { width: 600, height: 600 }; if (phantom.args.length === 3 && phantom.args[1].substr(-4) === ".pdf") { size = phantom.args[2].split('*'); page.paperSize = size.length === 2 ? { width: size[0], height: size[1], border: '0px' } : { format: phantom.args[2], orientation: 'portrait', border: '1cm' }; }/* xrays add */ else if(phantom.args.length === 3){ size = phantom.args[2].split('*'); page.viewportSize = { width: size[0], height: size[1] }; };/* end */ page.open(address, function (status) { if (status !== 'success') { console.log('Unable to load the address!'); } else { window.setTimeout(function () { page.render(output); phantom.exit(); }, 200); } }); } 

Then you can start writing VBScript'a. Create a file “wallpaper.vbs” in the folder “tools” and, to begin with, describe the necessary variables in it and fill in the important variables:
 Dim WshShell Set WshShell = WScript.CreateObject("Wscript.Shell") Dim url, history, logon '    url = "http://www.artmeteo.ru/4335/" '    history = 1 '     logon = 1 '      Windows 

I admit honestly, before that I did not write code on VBScript. In order to receive screenshots automatically you need to know the screen resolution:
 '    Dim obj, monSize Set obj = CreateObject("htmlfile") monSize = obj.parentWindow.screen.width & "*" & obj.parentWindow.screen.height 

Further:
 '    '    Dim toolsPath, path Set obj = CreateObject("Scripting.FileSystemObject") '     obj toolsPath = obj.GetParentFolderName(WScript.ScriptFullName) & "\" '      path = obj.GetParentFolderName(toolsPath) & "\" '     '        Dim phantom, bmpname phantom = toolsPath&"phantomjs\" '   phantomjs bmpname = path&"url.bmp " '   bmp  WshShell.Run phantom & "phantomjs.exe " & toolsPath & "rasterize.js " & url & " " & bmpname & monSize, 0, True '     

Notes: at the end of the last line, the parameters 0, True necessary for the code to be executed in the background and further commands described in the script are waiting for the execution of this code.
As you can see, the screenshot is saved in bmp format, this is done because versions of Windows OS under Vista do not perceive wallpaper in a different format. Next, we determine the OS version:
 Dim OSType OSType = Left(Trim(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")),1) '   windows Dim convert, n, time, jpgname, wallpaper 

Since the script should be as versatile as possible, but with different versions of the OS, you also need to reckon with, then first we describe the code for Windows Vista and 7:
 If OSType>5 Then '   Windows Vista  Windows 7 '   bmp  jpg Dim quality quality = 95 '   jpg  convert = toolsPath & "nconvert.exe -out jpeg -q " & quality & " -i -overwrite -o " n = Now '      time = Right("00" & Day(n), 2) & "-" & Right("00" & Month(n), 2) & "-" & Right("00" & Year(n), 2) & "_" & Right("00" & Hour(n), 2) & "_" & Right("00" & Minute(n), 2) & "_" & Right("00" & Second(n), 2) '   jpgname = path & time & ".jpg " '   jpg  WshShell.Run convert & jpgname & bmpname, 0, True '   bmp  jpeg '      wallpaper = WshShell.ExpandEnvironmentStrings("%APPDATA%") & "\Microsoft\Windows\Themes\TranscodedWallpaper.jpg" '    obj.CopyFile jpgname, wallpaper '  jpg   .   WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", wallpaper '           '   logon Dim logonname logonname = WshShell.ExpandEnvironmentStrings("%windir%") & "\System32\oobe\info\backgrounds\backgroundDefault.jpg " '   logon  If logon = 1 Then '    logon Dim logonconvert, goodlogon Set file = obj.GetFile(jpgname) '      logon If Round(file.size/1024) < 256 Then '    < 256,      goodlogon = 1 obj.CopyFile jpgname, logonname Else goodlogon = 0 quality = quality - 3 End If '     logon While goodlogon = 0 logonconvert = toolsPath & "nconvert.exe -out jpeg -q " & quality & " -i -overwrite -o " ' -canvas 1280 800 top-left WshShell.Run logonconvert & logonname & bmpname, 0, True Set file = obj.GetFile(logonname) '      logon If Round(file.size/1024) < 256 Then '   < 256 Kb,    goodlogon = 1 Else quality = quality - 3 '     End If Wend WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background\OEMBackground", 1, "REG_DWORD" Else If obj.FileExists(logonname) Then obj.DeleteFile logonname, True '  logon ,    End If End If If history = 0 Then '      ,   jpg  obj.DeleteFile jpgname, True End If WshShell.Run toolsPath & "wallpaper.exe", 0, True '  Windows      

You may notice that in this code there is a change in the logon image (picture of the welcome screen) to which the requirements of Windows apply. The essence of these requirements is that the file cannot be larger than 256 KB, therefore, a cycle starts to reduce the quality of the image until the permissible limit of the threshold is reached.
Now it’s time to describe the code for younger versions of Windows:
 Else '     Windows '      wallpaper = WshShell.ExpandEnvironmentStrings("%appdata%") & "\Wallpaper.bmp" '    obj.CopyFile bmpname, wallpaper '  bmp   .   WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", wallpaper '           '   logon Dim Background, Winlogon If logon = 1 Then '    logon Background = 1 Winlogon = 0 WshShell.RegWrite "HKEY_USERS\.DEFAULT\Control Panel\Desktop\TileWallpaper", 1, "REG_SZ" ' : (0 =  ; 1 =  ()) Else Background = 0 wallpaper = "" Winlogon = 1 End If WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background\OEMBackground", Background, "REG_DWORD" '     logon  WshShell.RegWrite "HKEY_USERS\.DEFAULT\Control Panel\Desktop\Wallpaper", wallpaper, "REG_SZ"'        logon  ' WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\LogonType", Winlogon, "REG_DWORD" ' 1 -   , 0 -      If history = 1 Then '     ,      bmp  jpg (95% ) convert = toolsPath & "nconvert.exe -out jpeg -q 95 -overwrite -o " n = Now time = Right("00" & Day(n), 2) & "-" & Right("00" & Month(n), 2) & "-" & Right("00" & Year(n), 2) & "_" & Right("00" & Hour(n), 2) & "_" & Right("00" & Minute(n), 2) & "_" & Right("00" & Second(n), 2) '   jpgname = path & time & ".jpg " WshShell.Run convert & jpgname & bmpname, 0, True '  bmp  jpg End If WshShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 0, True '        End If 

Final script fables:
 obj.DeleteFile bmpname, True '  bmp  Set WshShell = Nothing 

At this writing script is over. Automatic execution of the script, for example, every 5 minutes, will be done using the built-in Windows Task Scheduler. To do this, we create a new task and specify the path to the “wallpaper.vbs” script as the program to be started, and also do not forget to select daily and repeat every 5 minutes in the properties to trigger the trigger.

Results


The script has been tested on 2 computers with Windows 7, on one with Windows 2003 Server and on one with Windows XP. In order to see the changes in the welcome screen in Windows XP, you must either uncheck the “Use welcome page” item or uncomment the 100 line in the script source in the “Control Panel -> User Accounts -> Changes in Logged Users” box. The sources of the script, with all the additional software can be taken from here .
')

Updates


Now you can check the script on another computer with Windows 7, but the successful launch was not successful. The problem was that there was an error about the absence of the path to the file, which stores the picture of the welcome screen. Experimentally, a solution was found that consists either of manually creating the following path "%windir%\System32\oobe\info\backgrounds\" or changing the user account control settings (UAC) to the lowest, then restarting the computer and updating the script which can be downloaded here .

Source: https://habr.com/ru/post/132581/


All Articles