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

    Change desktop background color

    Scheduled Pinned Locked Moved Windows
    1 Posts 1 Posters 482 Views 1 Watching
    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.
    • RussR Offline
      Russ
      last edited by Russ

      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

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      • First post
        Last post