Skip to content

Commit

Permalink
Merge pull request #3 from Prajwal-Prathiksh/feat--add-reset-wallpape…
Browse files Browse the repository at this point in the history
…r-option

Feat  add reset wallpaper option
  • Loading branch information
Prajwal-Prathiksh authored Nov 11, 2024
2 parents bb70af5 + 621164a commit 0ca646b
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 4 deletions.
27 changes: 26 additions & 1 deletion BreakTheWall_GUI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ $srcDir = "$env:USERPROFILE\Downloads"
$updateSysParamsScript = "$PSScriptRoot\UpdateSystemParameters.ps1"
$oneTimeChangerScript = "$PSScriptRoot\OneTimeChanger.ps1"
$autoSchedulerScript = "$PSScriptRoot\SafeRunAutoScheduler.ps1"
$resetWallpaperScript = "$PSScriptRoot\ResetWallpaper.ps1"

# Check if srcDir\wallpaper.jpg exists
$srcFile = "$srcDir\wallpaper.jpg"
Expand Down Expand Up @@ -85,9 +86,33 @@ $btnOneTimeChanger.Add_Click({
[System.Windows.Forms.MessageBox]::Show("An error occurred: $($_.Exception.Message)")
}
})

$oneTimeTab.Controls.Add($btnOneTimeChanger)

$btnResetWallpaper = New-Object System.Windows.Forms.Button
$btnResetWallpaper.Text = "Reset Wallpaper"
$btnResetWallpaper.Font = New-Object System.Drawing.Font($btnResetWallpaper.Font, [System.Drawing.FontStyle]::Bold)
$btnResetWallpaper.Size = New-Object System.Drawing.Size($button_x, $button_y)
$btnResetWallpaper.Location = New-Object System.Drawing.Point($tabLeftOffset, 450)
$btnResetWallpaper.Add_Click({
try {
if (!(Test-Path -Path $resetWallpaperScript)) {
[System.Windows.Forms.MessageBox]::Show("Script not found in the expected location: $resetWallpaperScript")
return
}

# Run script
& $resetWallpaperScript
[System.Windows.Forms.MessageBox]::Show("Script executed - Wallpaper reset. Bye bye!")
& $updateSysParamsScript
$form.Dispose()
[System.Windows.Forms.Application]::Exit()
} catch {
# Display a detailed error message
[System.Windows.Forms.MessageBox]::Show("An error occurred: $($_.Exception.Message)")
}
})
$oneTimeTab.Controls.Add($btnResetWallpaper)

# Define and add controls to schedulerTab
$btnAutoutoScheduler = New-Object System.Windows.Forms.Button
$btnAutoutoScheduler.Text = "Run Auto Scheduled Wallpaper Changer"
Expand Down
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@ This repo offers a loophole to personalize your desktop background, allowing you
- The scripts are also designed to be non-intrusive and can be easily removed by simply deleting the entire repository from your system.

# Usage
## Clone Repository
To get started, you can clone this repository to your local machine by running the following command in your terminal:
```bash
git clone https://github.com/Prajwal-Prathiksh/BreakTheWall.git
```

If you don't have `git` installed, you can download the zip file and extract it to your desired location. *(If this is the first time you're working with `PowerShell` scripts, save and extract the repository in your `Downloads` directory, to simplify the process.)*


## GUI Mode (Recommended)
To change your wallpaper using the GUI, you can follow these steps:
1. Clone this repository to your local machine. If you don't have git installed, you can download the zip file and extract it. *(If this is the first time you're working with `PowerShell` scripts, save the script in your `Downloads` directory.)*
1. Save the image/images as per instructions in the [One-time Change](#one-time-change) or [Scheduled Change](#scheduled-change) sections.
1. **[Optional]** You can update the interval between wallpaper changes from the GUI itself. **By default, the interval is set to 1 hour.**
1. Run the [`BreakTheWall_GUI.ps1`](BreakTheWall_GUI.ps1) script by right-clicking on it and selecting `Run with PowerShell`. *(For pro-users, you can also run it from the `PowerShell` terminal, but make sure to navigate to the script's location first.)*

## One-time Change
You can use the [`OneTimeChanger.ps1`](OneTimeChanger.ps1) script to change your wallpaper to a custom one, as a one-time change. Here's how you can do it:
1. Clone this repository or download the zip file and extract it.
1. Store your desired wallpaper as `wallpaper.jpg` in the `Downloads` directory
> The script currently supports only `.jpg` files. If you have a different format, you can convert it to `.jpg` using an online converter, and the name must follow the format `wallpaper.jpg`.
Expand All @@ -32,7 +39,6 @@ You can use the [`OneTimeChanger.ps1`](OneTimeChanger.ps1) script to change your
## Scheduled Change
You can use the [`SafeRunAutoScheduler.ps1`](SafeRunAutoScheduler.ps1) script to keep changing your wallpapers at regular intervals automatically, from a set of saved wallpapers. Here's how you can do it:
1. Clone this repository or download the zip file and extract it.
1. Create a new folder named `custom_wallpapers` in the `Downloads` directory (Eg. `%USERPROFILE%\Downloads\custom_wallpapers`).
1. Store all the wallpapers you want to cycle through in the `custom_wallpapers` folder. **As mentioned before, the files must be in `.jpg` format only, but can have any name.**
1. **[Optional]** If you want to change the interval between wallpaper changes, you can modify the `AutoScheduler.vbs` script. **By default, the interval is set to 1 hour.**
Expand All @@ -43,6 +49,13 @@ You can use the [`SafeRunAutoScheduler.ps1`](SafeRunAutoScheduler.ps1) script to
> You can stop the script at any time by opening the `Task Manager` and ending the `Microsoft Windows Based Script Host` process.
## Reset to Default Wallpaper
If it ever becomes necessary for you to revert to the default wallpaper :"(, you can use the [`ResetWallpaper.ps1`](ResetWallpaper.ps1) script to do so. Here's how you can do it:
1. Run the `ResetWallpaper.ps1` script.

**That's it! Your wallpaper should now be updated to the default one .... :"(**


## Run scripts on Startup
If you want the scripts to run automatically every time you start your system, you can follow these steps:
1. In the directory where you cloned the repository, right-click on the `AutoScheduler.vbs` script and select `Create Shortcut`.
Expand Down
Binary file added README.pdf
Binary file not shown.
46 changes: 46 additions & 0 deletions ResetWallpaper.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<#
.SYNOPSIS
Resets the desktop wallpaper by removing the current transcoded wallpaper and cached files.
.DESCRIPTION
This script removes the current transcoded wallpaper and all cached wallpaper files from the specified directories.
It then calls another script to refresh the system parameters and reset the wallpaper.
.PARAMETER rootDir
The root directory where the transcoded wallpaper is stored.
.PARAMETER destDir
The destination directory where cached wallpaper files are stored.
.PARAMETER transcodedWallpaperDir
The directory of the current transcoded wallpaper.
.NOTES
The script uses environment variables to determine the paths for the root and destination directories.
.EXAMPLE
.\ResetWallpaper.ps1
This command runs the script to reset the desktop wallpaper.
#>
# Setup the root and destination paths for the wallpaper
$rootDir = "$env:APPDATA\Microsoft\Windows\Themes"
$destDir = "$env:APPDATA\Microsoft\Windows\Themes\CachedFiles"
$transcodedWallpaperDir = "$rootDir\TranscodedWallpaper"

# Remove the old transcoded wallpaper
if (Test-Path -Path $transcodedWallpaperDir) {
Remove-Item -Path $transcodedWallpaperDir -Force
Write-Host "Removed $transcodedWallpaperDir"
}

# Remove all files in the destination path
$files = Get-ChildItem -Path $destDir -File
foreach ($file in $files) {
Remove-Item -Path $file.FullName -Force
}
Write-Host "Removed all files in $destDir"

# Refresh the system parameters to reset the wallpaper
Start-Sleep -Seconds 2
.\UpdateSystemParameters.ps1
Write-Host "Refreshed desktop to reset wallpaper."

0 comments on commit 0ca646b

Please sign in to comment.