Created
December 14, 2020 08:20
-
-
Save vedantroy/41e55e2de0c7b08d7bfb734c10daa414 to your computer and use it in GitHub Desktop.
Add text to my desktop wallpaper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
import sys | |
import os | |
import shutil | |
import subprocess | |
if __name__ == "__main__": | |
args = sys.argv | |
if len(args) < 3: | |
print(f"Usage: set.py [image name] [text]") | |
exit(1) | |
image = args[1] | |
if not os.path.isfile(image): | |
print(f"No image at {image}") | |
exit(1) | |
text = args[2] | |
if text == "": | |
print("Text was empty") | |
exit(1) | |
size = '200' | |
if len(args) >= 4: | |
# ensure size is an int | |
size = str(int(args[3])) | |
else: | |
print(f"Size not provided as 3rd parameter using default value of: {size}") | |
temp = f"{image}.copy.png" | |
print("Adding text to copy...") | |
subprocess.run(f"convert {image} -gravity Center -fill \'#fff\' -pointsize {size} -annotate 0 \'{text}\' {temp}", shell=True, check=True) | |
img_path = "~/.config/background.png" | |
print("Copying the copy...") | |
subprocess.run(f"cp {temp} {img_path}", shell=True, check=True) | |
print("Setting background image...") | |
subprocess.run(f"feh --bg-fill {img_path}", shell=True, check=True) | |
print("Removing the copy...") | |
os.remove(temp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment