diff --git a/Scripts/Miscellaneous/Linux_Wallpaper_Changer/README.md b/Scripts/Miscellaneous/Linux_Wallpaper_Changer/README.md new file mode 100644 index 000000000..4242fdc92 --- /dev/null +++ b/Scripts/Miscellaneous/Linux_Wallpaper_Changer/README.md @@ -0,0 +1,27 @@ +# Linux Wallpaper Changer + +Python script which change the desktop wallpaper of Linux-based operating system. + +### Prerequisites + +The script does not need any external modules. It uses in-built python libraries like pathlib, sys, Tkinter, etc. + +### How to run the script + +Make sure you have Python 3.x installed on your machine then, +1. Go to **Scripts/Miscellaneous/Linux_Wallpaper_Changer** in *Command Prompt* or *Terminal* +2. Run the following command. + `python3 linux_wallpaper_changer.py` + or `python linux_wallpaper_changer.py` + + +### Screenshot/GIF showing the sample use of the script + +##### Before +![Screenshot-Before](https://i.postimg.cc/cCxVQ5gz/wallpaper-before.png) +##### After +![Screenshot-After](https://i.postimg.cc/HnbVynMz/wallpaper-after.png) + +## *Author Name* + +[Ritesh T](https://github.com/ritesh-dt) diff --git a/Scripts/Miscellaneous/Linux_Wallpaper_Changer/linux_wallpaper_changer.py b/Scripts/Miscellaneous/Linux_Wallpaper_Changer/linux_wallpaper_changer.py new file mode 100644 index 000000000..ca06621b8 --- /dev/null +++ b/Scripts/Miscellaneous/Linux_Wallpaper_Changer/linux_wallpaper_changer.py @@ -0,0 +1,58 @@ +from tkinter import Tk, Label, Button # from Tkinter import Tk for Python 2.x +from tkinter.filedialog import askopenfilename +import subprocess +from sys import platform +from pathlib import Path + +# Permitted Extensions +ALLOWED_EXTENSIONS = ['jpg', 'jpeg', 'png'] + +# Terminal command to change the background image (this may be different for different Linux distributions) +LINUX_TERMINAL_COMMAND = ["gsettings", "set", "org.gnome.desktop.background", "picture-uri"] +filename = None + +def get_file(): + global filename + filename = askopenfilename(title="Choose an image", filetypes=[("Image files", ("*.jpg", "*.jpeg", "*.png"))]) + + # Check for extension and if it is not allowed set the file to None + if not filename.split(".")[-1] in ALLOWED_EXTENSIONS: + print("Please select a JPEG/PNG file") + filename = None + + print("Selected Image: ", filename) + +def set_wallpaper(): + # Return if an image file is not selected + if filename is None: + return + # Identify the user's platform (Windows, Linux or Mac OS) + user_os = platform.lower() + + if user_os in ["linux", "linux2"]: + # Convert the image path into a file uri + file_uri = Path(filename).as_uri() + + # Execute the terminal command to change the wallpaper using the image's file uri + process = subprocess.Popen(LINUX_TERMINAL_COMMAND + [file_uri], stdout=subprocess.PIPE) + stdout = process.communicate() + process.terminate() + + # Check for any errors and print them + if stdout[1]: + print(stdout) + else: + print("Wallpaper Set Successfully!") + else: + print("Your operating system is currently not supported") + + +# Tkinter GUI +window = Tk() +window.title("Python World") +title = Label(text="Linux Wallpaper Changer", height=2, width=40).pack() + +# Buttons to get file path and set the wallpaper +file_chooser = Button(text="Choose an image (JPEG or PNG)", height=1, width=30, command=get_file).pack(pady=5) +submit_button = Button(text="Set as wallpaper", height=2, width=30, command=set_wallpaper).pack(pady=5) +window.mainloop() diff --git a/Scripts/Miscellaneous/Linux_Wallpaper_Changer/wallpaper_after.png b/Scripts/Miscellaneous/Linux_Wallpaper_Changer/wallpaper_after.png new file mode 100644 index 000000000..26ffc8167 Binary files /dev/null and b/Scripts/Miscellaneous/Linux_Wallpaper_Changer/wallpaper_after.png differ diff --git a/Scripts/Miscellaneous/Linux_Wallpaper_Changer/wallpaper_before.png b/Scripts/Miscellaneous/Linux_Wallpaper_Changer/wallpaper_before.png new file mode 100644 index 000000000..ee9c0dfa4 Binary files /dev/null and b/Scripts/Miscellaneous/Linux_Wallpaper_Changer/wallpaper_before.png differ