Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Added wallpaper setter to System Automation Scripts #175

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions System-Automation-Scripts/Wallpaper Setter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Wallpaper setter


#### This script can be used to change the wallpaper on a **Windows PC**.It takes a jpg file as input and sets it as the desktop wallpaper

#### How to use this script?

Go to the commant prompt and type the following :

python Wallpaper.py -l "Your_jpg_file"

Example :

python Wallpaper.py -l awesome.jpg

#### Output you get:

Your desktop wallpaper gets changed

#### PS: Provide absolute path if the wallpaper is in other directory than the current one. Would prefer running this script from wallpaper folder.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions System-Automation-Scripts/Wallpaper Setter/wallpaper_setter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import ctypes
import os
import argparse
import sys

# Code to add the cli
parser = argparse.ArgumentParser()
parser.add_argument("-l", "--jpgfile", required=True, help="JPG File")
args = vars(parser.parse_args())


#Storing the absolute path of the jpg file provided by the user
filename = args['jpgfile']

# To make sure a jpg file has been provided
if filename.endswith(".jpg"):



# Code to get the absolute path of the jpg file
def getabsolutepath(filename):
path = os.path.abspath(filename)
return path

#The code for setting wallpaper in SystemParametersInfoW function is 20
SPI_SETDESKWALLPAPER = 20

#Main code to change the wallpaper
output_from_wallpaper_change = ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, getabsolutepath(filename), 0)

if output_from_wallpaper_change == 1:
print("Your wallpaper has been changed successfully!!!")
else:
print("Sorry cant set this file as your wallpaper")
else:
sys.exit("Enter a jpg file only please")