Created
October 23, 2022 19:52
-
-
Save jlovald/cf89ee55c24968d3d4c2f287aafb7beb to your computer and use it in GitHub Desktop.
This file contains 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
import json | |
import glob | |
import os | |
import re | |
import random | |
## Get Settings. | |
dirname = os.path.dirname(os.path.realpath(__file__)) | |
f = open(f'{dirname}/settings.json') | |
data = json.load(f) | |
profileGuid=data["ProfileGuid"] | |
terminalSettingsPath = data["TerminalSettingsPath"] | |
backgroundImagePath = data["BackgroundsPath"] | |
# Get JPGs and PNGs from image folder. | |
jpgs = glob.glob(f"{backgroundImagePath}/*.jpg") | |
pngs = glob.glob(f"{backgroundImagePath}/*.png") | |
jpgs.extend(pngs) | |
backgrounds = jpgs | |
f.close() | |
windowsPaths = list(backgrounds) | |
# Update settings. | |
with open(terminalSettingsPath, "r+") as f: | |
data = json.load(f) | |
profiles = data["profiles"]["list"] | |
# Get profile with guid. | |
elem = next(filter(lambda profile: profile["guid"] == profileGuid, profiles), None) | |
random.shuffle(windowsPaths) | |
# Find first non-matching image, don't want duplicates | |
windowsPaths = [value for value in windowsPaths if value != elem["backgroundImage"]] | |
elem["backgroundImage"] = windowsPaths[0] | |
f.seek(0) # <--- should reset file position to the beginning. | |
json.dump(data, f, indent=4) | |
f.truncate() |
This file contains 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
{ | |
"TerminalSettingsPath": "C:\\Users\\Elmer\\AppData\\Local\\Packages\\Microsoft.WindowsTerminal_8wekyb3d8bbwe\\LocalState\\settings.json", | |
"BackgroundsPath": "C:\\Terminal\\Backgrounds", | |
"ProfileGuid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment