[Batch]Day/Night theme switch for Sumatra PDF #799
custard-pi
started this conversation in
Custom scripts
Replies: 1 comment
-
rewrote with pwsh, no longer requires FART.
#SumatraPDF Day/Night Mode Switcher
# Check the argument passed in
$argument = $args[0]
# Read the content of the config file
$configFile = "$env:LOCALAPPDATA\SumatraPDF\SumatraPDF-settings.txt"
$configContent = Get-Content $configFile
$preferedLightTheme = "Light" # Change this to your prefered light theme
$preferedDarkTheme = "Darker" # Change this to your prefered dark theme
# Perform different tasks based on the argument
switch ($argument) {
"-L" {
# Switch to dark theme
# Find and replace the configuration
$newConfigContent = $configContent -replace "^Theme = $preferedDarkTheme$", "Theme = $preferedLightTheme"
# Write the updated content back to the config file
$newConfigContent | Set-Content $configFile
}
"-D" {
# Switch to light theme
# Find and replace the configuration
$newConfigContent = $configContent -replace "^Theme = $preferedLightTheme$", "Theme = $preferedDarkTheme"
# Write the updated content back to the config file
$newConfigContent | Set-Content $configFile
}
default {
Write-Host "Invalid argument."
}
} 2.scripts.yaml Enabled: true
Component:
Scripts:
- Name: SumatraPDF
Command: pwsh
WorkingDirectory: "{directory where ThemeSwitch.ps1 is stored in}"
ArgsLight: [./ThemeSwitch.ps1, -L]
ArgsDark: [./ThemeSwitch.ps1, -D]
AllowedSources: [Any] |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Auto Day/Night theme switch for Sumatra PDF (Github)
Sumatra PDF uses a text file(%LOCALAPPDATA%\SumatraPDF\SumatraPDF-settings.txt) to store all its settings.
In the settings file, "Theme = "string defines the theme used by the program, currently three themes are available:
"Theme = Light"
"Theme = Dark"
"Theme = Darker"
This script use FART (Find And Replace Text command line utility) to replace theme settings in the settings file, switching the theme.
1.Save the following batch script as a .bat file (e.g.
C:\\Mydir\ThemeSwitch.bat
).You can use "Theme = Dark" instead of "Theme = Darker" if you prefer the Dark theme as the night theme.
2. Download the latest release of FART, save the fart.exe in the same directory as the bat file(e.g.
C:\\Mydir\fart.exe
).3. Paste the following content into
scripts.yaml
replace
{Path of the .bat}
to the path of the bat file(e.g.C:\\Mydir\ThemeSwitch.bat
).Beta Was this translation helpful? Give feedback.
All reactions