• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
TRIGGERcmd
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Change desktop background color

Windows
1
1
150
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R
    Russ
    last edited by Russ Oct 10, 2023, 1:23 AM Oct 10, 2023, 1:17 AM

    You can use this with the TRIGGERcmd Smart Home skill's ability to pass a color as the parameter (not just on or off).

    param (
        [string]$ColorName = "red"
    )
    
    # Define a hashtable mapping color names to hexadecimal color codes
    $ColorHexMap = @{
        "red" = "0x2a2490"
        "blue" = "0xFF0000"
        "green" = "0x008000"
        "purple" = "0xA52A2A"
        "yellow" = "0x70ffe6"
        "brown" = "0x2d4159"
        "black" = "0x000000"
        "white" = "0xFFFFFF"
    }
    
    # Check if the provided color name exists in the hashtable
    if ($ColorHexMap.ContainsKey($ColorName)) {
        $ColorHex = $ColorHexMap[$ColorName]
    } else {
        Write-Host "Invalid color name. Please use 'red,' 'blue,' 'green' etc."
        exit
    }
    
    Add-Type -TypeDefinition @"
        using System;
        using System.Runtime.InteropServices;
        
        public class PInvoke {
            [DllImport("user32.dll")]
            public static extern bool SetSysColors(int cElements, int[] lpaElements, int[] lpaRgbValues);
        }
    "@
    
    [PInvoke]::SetSysColors(1, @(1), @($ColorHex))
    

    When I said, Alexa, turn desktop green it turned my desktop green:
    204af707-e75b-48b6-bc03-6837ae9d0ef2-image.png

    When I said, Alexa, turn desktop blue it turned my desktop blue:
    63d707db-788b-4f51-9f81-540c42521b29-image.png

    Russell VanderMey

    1 Reply Last reply Reply Quote 0
    1 out of 1
    • First post
      1/1
      Last post