Skip to content

Commit 2a3ce4d

Browse files
v1.0.39
- MAJOR UPDATE: - Added a native system to load Dark or Light modes and randomize wallpapers. Though `.theme` files can still be used, see config file - Renamed the script at.ps1 for consistency with my other short-named projects. - Added a wrapper script (`AutoTheme.ps1`) for compatibility with older tasks and existing shortcuts. - Fixed a problem with the script not recognizing it was running from Task Scheduler - Improved geolocation - Many minor fixes
1 parent 83fcb91 commit 2a3ce4d

4 files changed

Lines changed: 71 additions & 58 deletions

File tree

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,50 @@
1-
# ============= User variables =============
21

3-
# Name of theme files
2+
# ============= Theme variables =============
3+
4+
<# If `$true`, the script will use `.theme` files to select light and dark themes, as well as
5+
wallpaper slideshows and other personalizations. If `$false`, it will use its native system
6+
to switch between dark and light modes, and implement a wallpaper slideshow accordingly. #>
7+
$useThemeFiles = $true
8+
9+
<# Name of theme files
10+
* Only relevant when `$useThemeFiles = $true` #>
411
$themeLight = "Name-of-Light.theme"
512
$themeDark = "Name-of-Dark.theme"
613

7-
<# Complete path to the `.theme` files. You can use the default path to Windows themes
14+
<# COMPLETE PATH to the `.theme` files. You can use the default path to Windows themes
815
(as proposed in the example below) or a custom path of your choice.
9-
Consider that Windows will always copy your `.theme` files to LocalAppData.
10-
You can use something like `$lightPath = Join-Path $PSScriptRoot $themeLight`
11-
if your `.theme` files are located within the script folder. #>
16+
You can use `$lightPath = Join-Path $PSScriptRoot $themeLight`
17+
if your `.theme` files are located within the script folder.
18+
* Only relevant when `$useThemeFiles = $true` #>
1219
$lightPath = Join-Path (Join-Path $Env:LOCALAPPDATA "Microsoft\Windows\Themes") $themeLight
1320
$darkPath = Join-Path (Join-Path $Env:LOCALAPPDATA "Microsoft\Windows\Themes") $themeDark
1421

22+
# ============= Wallpaper variables =============
23+
24+
<# If `$true`, the script will only switch between Dark and Light modes, ignoring wallpapers.
25+
* Only relevant when `$useThemeFiles = $false` #>
26+
$noWallpaperChange = $false
27+
28+
<# Randomize first wallpaper.
29+
Even if `shuffle=1` is set in a `.theme` file, Windows will always use
30+
the first wallpaper in alphabetic order as the first shown.
31+
Setting this to $true offers more variety as soon as the theme is applied.
32+
Be aware that, to this end, a randomly-picked wallpaper file
33+
will be temporarily renamed with a "0_AutoTheme" string prepended to it.
34+
* Only relevant when `$useThemeFiles = $true` #>
35+
$randomFirst = $true
36+
37+
<# Paths to the folders for light and dark wallpapers.
38+
If `$useThemeFiles = $true`, indicate here the same paths indicated in the `.theme` files.
39+
If `$useThemeFiles = $false`, indicate paths to images or folders to be selected for Light and Dark modes. #>
40+
$wallLightPath = "C:\Path\to\Light\wallpapers"
41+
$wallDarkPath = "C:\Path\to\Dark\wallpapers"
42+
43+
# Show the wallpaper name in notification
44+
$showWallName = $true
45+
46+
# ============= Time variables =============
47+
1548
# Use fixed hours to switch Themes (keeps the script completely offline)
1649
$useFixedHours = $false
1750

@@ -20,53 +53,34 @@
2053
$lightThemeTime = "07:00 AM"
2154
$darkThemeTime = "07:00 PM"
2255

23-
<# Set to $true to always use a user-defined location.
24-
Alernatively, the script will attempt to retrieve location from the system
56+
<# Set to `$true` to always use a user-defined location.
57+
If `$false`, the script will attempt to retrieve location from the system
2558
or, failing that, from your ISP, which may not give accurate results. #>
2659
$useUserLoc = $false
2760

2861
<# User-defined coordinates and timezone. You can obtain your coordinates from Google or similar services.
2962
You can find a list of timezone identifiers at this url:
30-
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
31-
(These values are only retrieved if $UseUserLoc = $true and $useFixedHours = $false.
32-
Yet, better set them, as the script will fall back to them, if all else fails.) #>
63+
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
64+
* Only relevant if `$useUserLoc = $true`#>
3365
$userLat = "40.7128"
3466
$userLng = "-74.0060"
3567
$UserTzid = "America/New_York"
3668

3769
<# Add or remove minutes to Sunrise and Sunset times. This can help
38-
to account for local peculiarities
39-
. Values can be negative,
70+
to account for local peculiarities. Values can be negative,
4071
for example, -30 means the event triggers 30 minutes earlier. #>
4172
$sunriseOffset = 0
4273
$sunsetOffset = 0
4374

44-
<# Randomize first wallpaper.
45-
Even if 'shuffle=1' is set in a `.theme` file, Windows will always use
46-
the first wallpaper in alphabetic order as the first shown.
47-
Setting this to $true offers more variety as soon as the theme is applied.
48-
Be aware that, to this end, a randomly-picked wallpaper file
49-
will be temporarily renamed with a "0_AutoTheme" string prepended to it. #>
50-
$randomFirst = $true
51-
52-
<# Paths to the folders for light and dark wallpapers.
53-
(only needed if $randomFirst = true)
54-
Use the same ones indicated in your .theme files. #>
55-
$wallLightPath = "C:\Path\to\Light\wallpapers"
56-
$wallDarkPath = "C:\Path\to\Dark\wallpapers"
57-
58-
# Show the wallpaper name in notification
59-
$showWallName = $true
60-
6175
# ============= Extra apps variables =============
6276

6377
<# Sysinternals Process Explorer doesn't automatically change theme when
6478
the system theme is changed. Use this variable if you want it to be restarted.
6579
If you run Process Explorer as Admin, the script should also run as Admin for this to work.
6680
You can use the $forceAsAdmin variable below for the purpose. #>
6781
$restartProcexp = $false
68-
# If true, Process Explorer will keep Admin rights (inheriting from this script).
69-
# If false, it will be restarted as a standard user. All other apps are restarted as standard user.
82+
# If `$true`, Process Explorer will keep Admin rights (inheriting from this script).
83+
# If `$false`, it will be restarted as a standard user. All other apps are restarted as standard user.
7084
$restartProcexpElevated = $true
7185

7286
<# Change TrueLaunchBar colors (will cause Explorer to be restarted)
@@ -78,11 +92,11 @@
7892
$restartMusicBee = $false
7993

8094
<# Changes color in the T-Clock font, so that it adapts to the current theme.
81-
Regarding this app, be aware that when T-Clock redraws the clock background based on accent color,
82-
it may cause the taskbar to crash or flicker. Better avoid it. #>
95+
When T-Clock redraws the clock background based on accent color,
96+
it may cause the taskbar to crash or flicker. #>
8397
$tClockPath = "C:\Path\to\T-Clock\Clock64.exe"
8498
$updateTClockColor = $false
85-
$restartTClockColor = $false
99+
$restartTClockColor = $false # usually not needed
86100

87101
# ============= Developer variables ==============
88102

@@ -93,20 +107,20 @@
93107
$lastRunInterval = "5"
94108
$waitExplorer = "30"
95109
$checkLastRun = $true
96-
$maxLogEntries = "20"
110+
$maxLogEntries = "5"
97111

98-
# Turn this off if you have surge issues when switching theme or wallpaper
112+
# Try turning accent color off if you have surge issues when switching theme or wallpaper
99113
$turnOffAccentColor = $false
100114

101115
$restartThemeService = $false
102116
$forceAsAdmin = $false
103117

104-
$appLogo = Join-Path $PSScriptRoot "AutoTheme.png"
105-
$logFile = Join-Path $PSScriptRoot "AutoTheme.log"
106-
$lastRunFile = Join-Path $PSScriptRoot "ATLastRun.txt"
107-
108-
# Console Visibility Settings when run from Task Scheduler
109-
# "ch" - Completely hidden (no flash) using conhost --headless
110-
# "ps" - Standard PowerShell window (may flash briefly)
111-
# "wt" - Opens in Windows Terminal (using existing window if open)
112-
$terminalVisibility = "ch"
118+
$appLogo = Join-Path $PSScriptRoot "at.png"
119+
$logFile = Join-Path $PSScriptRoot "at.log"
120+
$lastRunFile = Join-Path $PSScriptRoot "at-lastRun.txt"
121+
122+
<# Console Visibility Settings when run from Task Scheduler:
123+
* "ch"- Completely hidden (no flash) using `conhost --headless`
124+
* "ps"- Standard PowerShell window (may flash briefly)
125+
* "wt"- Opens in Windows Terminal (using existing window if open) #>
126+
$terminalVisibility = "ch"

Setup.ps1 renamed to at-setup.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,17 @@
9090
LogThis "This script requires administrative privileges. Requesting elevation..." -Level Warning
9191
# -NoProfile to ensure a clean environment during elevation
9292
$proc = Start-Process -FilePath "powershell.exe" `
93-
-ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" `
94-
-Verb RunAs -PassThru
93+
-ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" `
94+
-Verb RunAs -PassThru
9595
# Exit the non-elevated instance
9696
Exit 0
9797
}
9898

99-
# Define the path to the AutoTheme.ps1 script and task XML file
100-
$AutoThemeScript = Join-Path -Path $PSScriptRoot -ChildPath "AutoTheme.ps1"
99+
# Define the path to the at.ps1 script and task XML file
100+
$AutoThemeScript = Join-Path -Path $PSScriptRoot -ChildPath "at.ps1"
101101
$TaskName = "Auto Theme"
102102

103-
# Check if AutoTheme.ps1 exists
103+
# Check if at.ps1 exists
104104
if (!(Test-Path $AutoThemeScript)) {
105105
LogThis "Required script file '$AutoThemeScript' not found. Exiting setup..." -Level Error
106106
Pause
File renamed without changes.

at.ps1

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
Alternatively, it can stay completely offline operating on fixed hours provided by the user.
1414
When ran as the command `./at.ps1` from terminal or desktop shortcut, the script will only toggle between themes.
1515
IMPORTANT: Edit `Config.ps1` to configure this script. The file contains all necessary explanations.
16-
OPTIONALLY: Run `./Setup.ps1` to create the main Scheduled Task, or create one manually in Task Scheduler.
16+
OPTIONALLY: Run `./setup.ps1` to create the main Scheduled Task, or create one manually in Task Scheduler.
1717
For more information, refer to the README file.
1818
1919
.LINK
2020
https://github.com/unalignedcoder/auto-theme/
2121
2222
.NOTES
2323
- MAJOR UPDATE:
24-
- Added a native system to load Dark or Light modes and randomize wallpapers. `.theme` files can still be used, see config file
24+
- Added a native system to load Dark or Light modes and randomize wallpapers. Though `.theme` files can still be used, see config file
2525
- Renamed the script "at.ps1" for consistency with my other "short-named" projects.
2626
- Added a "wrapper" script (`AutoTheme.ps1`) for compatibility with older tasks and existing shortcuts.
2727
- Fixed a problem with the script not recognizing it was running from Task Scheduler
@@ -32,11 +32,11 @@
3232
# ============= Script Version ==============
3333

3434
# This is automatically updated
35-
$scriptVersion = "1.0.38"
35+
$scriptVersion = "1.0.39"
3636

3737
# ============= Config file ==============
3838

39-
$ConfigPath = Join-Path $PSScriptRoot "Config.ps1"
39+
$ConfigPath = Join-Path $PSScriptRoot "config.ps1"
4040

4141
# ============= Win32 API Definitions ==============
4242

@@ -881,9 +881,7 @@ if (-not ([System.Management.Automation.PSTypeName]'WinAPI').Type) {
881881
if (-Not ($IsAdmin)) {
882882

883883
Write-Host "This script requires administrative privileges. Requesting elevation..." -ForegroundColor Yellow
884-
Start-Process -FilePath "powershell.exe" `
885-
-ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" `
886-
-Verb RunAs
884+
Start-Process -FilePath "powershell.exe" -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
887885
Exit 0
888886
}
889887
}
@@ -1634,3 +1632,4 @@ if (-not ([System.Management.Automation.PSTypeName]'WinAPI').Type) {
16341632
}
16351633

16361634

1635+

0 commit comments

Comments
 (0)