Log inRegister

Desktop and browser backgrounds

26 October 2024 - 11:03 | Version 4 |

Since 2021, I create two monthly car calendars, one with modern/contemporary cars, and one with classic cars.

I use them on some desktop devices and in some browsers. In order to automate the monthly switch, I have created a cron job which changes the picture on the first day of the month using the script !NewMonth.sh:
export calpic=`date +%y%m`
export here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cp $here/$calpic.jpg $here/myBackground.jpg

In the DirectAdmin Web Control Panel of your hosting provider, you can add a cron job here:
  • Advanced Features > Cron Jobs

Change Firefox browser background image

https://support.mozilla.org/en-US/questions/1271362

see here: BrowserExtensions

Scheduled Task 'Background Change Monthly'

PowerShell script
(staat op mijn OneDrive in Cars\Wallpapers\CurYear):
#------------------------------------------------------------------------------#
# ScriptName : B(ack)g(round)ChangeMonthly.ps1                                 #
# Description : Change the background every month based on screen resolution   #
#                                                                              #
# Date : 04 December 2023                                                      #
# Version 0.6                                                                  #
# Solution for the annumbug :-)                                                #
# Date : 23 April 2021                                                         #
# Version 0.5                                                                  #
# Solution for the wrong resolution for my Surface 3 (1280x853)                #
# see: https://superuser.com/questions/1436909/how-to-get-the-current-screen-resolution-on-windows-via-command-line
# Version 0.4                                                                  #
# using the OneDrive env var so I can use the script on multiple devices       #
# see: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.1
# Version 0.3                                                                  #
# execute PowerShell scripts from the Task Scheduler                           #
# see: https://community.spiceworks.com/how_to/17736-run-powershell-scripts-from-task-scheduler
# Version 0.2                                                                  #
# overcome the inconsistent results with UpdatePerUserSystemParameters         #
# based on option 2 from this site: https://c-nergy.be/blog/?p=15291           #
# different image per screen resolution approach                               #
# based on: https://aventistech.com/2018/07/20/powershell-desktop-wallpaper-based-on-resolution-size/
# and more recent -eq comparison operator                                      #
# see: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_if?view=powershell-7.1
# and: https://www.computerperformance.co.uk/powershell/comparison-operators/  #
# Version 0.1                                                                  #
# based on: https://stackoverflow.com/questions/46984616/how-to-set-wallpaper-from-windows-command-prompt-on-windows-10
#                                                                              #
# IMPORTANT: run .vbs with "Run only when user is logged on" in Task Scheduler #
#------------------------------------------------------------------------------#

$PTimestamp = Get-Date -Format "dd/MM/yyyy HH:mm:ss"
$DateStr = Get-Date -Format "yyMM"
$OneDrive = $Env:OneDrive
$ComputerName = $env:computername
$log = '------------ launch BgChangeMonthly.ps1 = ' + $PTimestamp + ' ------------'
echo $log | Out-File $OneDrive\Cars\Wallpapers\CurYear\$ComputerName-BgChangeMonthly.log -encoding ASCII -Append

#Get the screen resolution 
Add-Type -AssemblyName System.Windows.Forms
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class PInvoke {
    [DllImport("user32.dll")] public static extern IntPtr GetDC(IntPtr hwnd);
    [DllImport("gdi32.dll")] public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
}
"@
$hdc = [PInvoke]::GetDC([IntPtr]::Zero)
$Resolution= "{0}x{1}" -f 
[PInvoke]::GetDeviceCaps($hdc, 118), # width
[PInvoke]::GetDeviceCaps($hdc, 117) # height

# Apply Desktop Wallpaper based on the Screen Resolution
# Full HD on my Dell Studio XPS 1647 
if ($Resolution -eq "1920x1080") {
   #Modify Path to the picture accordingly to reflect your infrastructure
   #$imgPath="$OneDrive\Cars\Wallpapers\CurYear\16-9ancient-tiny\$DateStr.png"
   $imgPath="$OneDrive\Cars\Wallpapers\CurYear\16-9modern-tiny\$DateStr.png"
}
# 1920x1280 on my Surface 3
if ($Resolution -eq "1920x1280") {
   #Modify Path to the picture accordingly to reflect your infrastructure
   #$imgPath="$OneDrive\Cars\Wallpapers\CurYear\3-2modern-tiny\$DateStr.png"
   $imgPath="$OneDrive\Cars\Wallpapers\CurYear\3-2ancient-tiny\$DateStr.png"
}
#TEST
$log = 'Resolution = ' + $Resolution
echo $log | Out-File $OneDrive\Cars\Wallpapers\CurYear\$ComputerName-BgChangeMonthly.log -encoding ASCII -Append
$log = 'imgPath = ' + $ImgPath
echo $log | Out-File $OneDrive\Cars\Wallpapers\CurYear\$ComputerName-BgChangeMonthly.log -encoding ASCII -Append
#Pause

$code = @' 
using System.Runtime.InteropServices; 
namespace Win32{ 

     public class Wallpaper{ 
        [DllImport("user32.dll", CharSet=CharSet.Auto)] 
         static extern int SystemParametersInfo (int uAction , int uParam , string lpvParam , int fuWinIni) ; 

         public static void SetWallpaper(string thePath){ 
            SystemParametersInfo(20,0,thePath,3); 
         }
    }
 } 
'@

add-type $code 

#Apply the Change on the system 
[Win32.Wallpaper]::SetWallpaper($imgPath)

$PTimestamp = Get-Date -Format "dd/MM/yyyy HH:mm:ss"
$log = '------------ finish BgChangeMonthly.ps1 = ' + $PTimestamp + ' ------------'
echo $log | Out-File $OneDrive\Cars\Wallpapers\CurYear\$ComputerName-BgChangeMonthly.log -encoding ASCII -Append

tags

wallpaper
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback