0
\$\begingroup\$

I made myself a simple script (Batch/JScript) that download a pic from a blog (APOD) & set it as wallpaper.

@if (@a==@b) @end /*

Set BaseUrl=https://apod.nasa.gov/apod/
set yr=%date:~8,2%
set mn=%date:~3,2%
set dy=%date:~0,2%
set dte=%yr%%mn%%dy%
set SaveDest=C:\Users\ME\Desktop\Wallpaper\%dte%.jpg
Set Url=%baseUrl%ap%dte%.html


@echo off
setlocal
for /f "delims=" %%I in ('cscript /nologo /e:jscript "%~f0" "%Url%"') do (
    rem 
    echo %%I
    set LastImg=%%I
)

set ImgUrl=%BaseUrl%%LastImg:~6%
bitsadmin.exe /transfer GETWALLPAPER %ImgUrl% %SaveDest%
timeout /t 01
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d %savedest% /f
timeout /t 01
for /l %%x in (1,1,80) do  (
RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d %savedest% /f
timeout /t 01
)

goto :EOF

JScript */
function fetch(url) {
    var xhr=WSH.CreateObject("Microsoft.XMLHTTP");
    var dom=WSH.CreateObject('htmlfile');
    xhr.open("GET",WSH.Arguments(0),true);
    xhr.setRequestHeader('User-Agent','XMLHTTP/1.0');
    xhr.send('');
    while (xhr.readyState!=4) {WSH.Sleep(25)};
    dom.write('<meta http-equiv="x-ua-compatible" content="IE=9" />');
    dom.write(xhr.responseText);
    return dom;
}
var dom=fetch(WSH.Arguments(0));
var link=dom.getElementsByTagName('IMG');

WSH.Echo(link[0].src);

It's working. However, I am unhappy about the for /l %%x in (1,1,80) d loop: it seems not to work without the loop. Any Idea ?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.