Skip to content

Instantly share code, notes, and snippets.

@hackedd
Last active January 2, 2016 00:09
Show Gist options
  • Save hackedd/8221565 to your computer and use it in GitHub Desktop.
Save hackedd/8221565 to your computer and use it in GitHub Desktop.
Replace default date and time format in cinnamon-screensaver
import sys
source = "/usr/bin/cinnamon-screensaver"
time_format = "%l:%M %p"
date_format = "%A, %B %e"
nul = "\x00"
def patch(data, orig, new):
assert len(orig) >= len(new), repr(new) + " too long"
o, l = data.find(orig), len(orig)
assert o >= 0, repr(orig) + " not found"
return data[:o] + new.ljust(l, nul) + data[o + l:]
new_time_format = sys.argv[1] if len(sys.argv) >= 2 else "%T"
new_date_format = sys.argv[2] if len(sys.argv) >= 3 else "%c"
dest = sys.argv[3] if len(sys.argv) >= 4 else "cinnamon-screensaver"
with open(source, "rb") as fp:
data = fp.read()
data = patch(data, time_format, new_time_format)
data = patch(data, date_format, new_date_format)
with open(dest, "wb") as fp:
fp.write(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment