Skip to content

Commit

Permalink
MacOS Sonoma update
Browse files Browse the repository at this point in the history
  • Loading branch information
robwaz committed Oct 21, 2023
1 parent 236aa48 commit 91a8b3b
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pywal/wallpaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import shutil
import subprocess
import urllib.parse
import plistlib
import datetime
import tempfile

from .settings import HOME, OS, CACHE_DIR
from . import util
Expand Down Expand Up @@ -167,6 +170,58 @@ def set_mac_wallpaper(img):
subprocess.call(["killall", "Dock"])


# MacOS Sonomoa uses a plist file instead. Interestingly the database referenced above
# still exists, but doesn't seem to do anyything on Sonoma, so lets leave it for backward
# compatability

plist_path = "Library/Application Support/com.apple.wallpaper/Store/Index.plist"
plist_path = os.path.join(HOME, plist_path)

# Write a backup of plist file in temp in case something horrific happens
with open(plist_path, 'rb') as f:
old_plist = plistlib.load(f)
with tempfile.NamedTemporaryFile(prefix="pywal-plist-bk-", delete=False) as g:
logging.info(f"Backup plist file saved to {g.name}")
plistlib.dump(old_plist, g)

# Unfortunately these fields seem mandatory. not extensively tested
# - Configuration is a plist unto itself and a value is required
with open(plist_path, 'wb') as f:
new_plist = {'Spaces': {},
'SystemDefault': {'Desktop': {'LastSet': datetime.datetime.now(),
'LastUse': datetime.datetime.now(),
'Content': {'Choices': [{'Provider': 'com.apple.wallpaper.choice.image',
'Files': [{'relative': f'file:///{img}'}],
'Configuration': b''}],
'Shuffle': '$null'}},
'Type': 'individual',
'Idle': {'LastSet': datetime.datetime.now(),
'LastUse': datetime.datetime(2023, 10, 21, 2, 51, 4, 435303),
'Content': {'Choices': [{'Provider': 'com.apple.wallpaper.choice.aerials',
'Files': [],
'Configuration': b''}],
'Shuffle': {'Type': 'afterDuration',
'Duration': [2341, 16172123445939666944]}}}},
'Displays': {},
'AllSpacesAndDisplays': {'Desktop': {'LastSet': datetime.datetime.now(),
'LastUse': datetime.datetime.now(),
'Content': {'Choices': [{'Provider': 'com.apple.wallpaper.choice.image',
'Files': [{'relative': f'file:///{img}'}],
'Configuration': b'bplist00\xd2\x01\x02\x03\x0c_\x10\x0fbackgroundColorYplacement\xd2\x04\x05\x06\x0bZcomponentsZcolorSpace\xa4\x07\x08\t\n#?\xd0PPPPPP#?\xdaZZZZZZ#?\xe5UUUUUU#?\xf0\x00\x00\x00\x00\x00\x00O\x10Cbplist00_\x10\x17kCGColorSpaceGenericRGB\x08\x00\x00\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"\x10\x01\x08\r\x1f).9DIR[dm\xb3\x00\x00\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\r\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb5'}],
'Shuffle': '$null'},
'Last': datetime.datetime.now()},
'Type': 'individual',
'Idle': {'LastSet': datetime.datetime.now(),
'LastUse': datetime.datetime.now(),
'Content': {'Choices': [{'Provider': 'com.apple.wallpaper.choice.aerials',
'Files': [],
'Configuration': b''}],
'Shuffle': {'Type': 'afterDuration',
'Duration': [2341, 16172123445939666944]}}}}}
plistlib.dump(new_plist,f)
f.close()
subprocess.call(["killall", "WallpaperAgent"])

def set_win_wallpaper(img):
"""Set the wallpaper on Windows."""
# There's a different command depending on the architecture
Expand Down

0 comments on commit 91a8b3b

Please sign in to comment.