From fb52015445230f51e5f0b3e59f2e65fba8ce526b Mon Sep 17 00:00:00 2001 From: raute Date: Thu, 9 May 2024 00:15:01 +0200 Subject: [PATCH] Add support for MacOS. --- README.md | 3 ++- llplenum | 29 ++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9ba71b8..5ad658e 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,5 @@ A simple script to format the minutes of a plenum (Markdown) for the LeineLab wi Copy the Markdown code to clipboard and call this script. You'll the find the modified code in your clipboard, ready to paste. ## Dependencies -- xclip +- xclip (Linux) +- pbcopy/pbpaste (MacOS) diff --git a/llplenum b/llplenum index 76f7eec..ab145a4 100755 --- a/llplenum +++ b/llplenum @@ -1,20 +1,43 @@ #!/usr/bin/env python3 import datetime +import platform import re import subprocess import sys +def get_clipboard(): + if platform.system() == "Darwin": + return subprocess.check_output(["pbpaste"]).decode() + + return subprocess.check_output(["xclip", "-out", "-selection", "clipboard"]).decode() + + +def set_clipboard(content): + if platform.system() == "Darwin": + subprocess.run(["pbcopy"], input=content.encode()) + return + + subprocess.run(["xclip", "-in", "-selection", "clipboard"], input=content.encode()) + + +# main +if platform.system() not in ["Darwin", "Linux"]: + print("Nicht unterstütztes Betriebssystem.", file=sys.stderr) + sys.exit(1) + months = ["", "Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"] -clipboard = subprocess.check_output(["xclip", "-out", "-selection", "clipboard"]).decode() +clipboard = get_clipboard() -m = re.match(r"# ([0-9][0-9]+)\. Plenum .+ ([0-9]{1,2})\. (" + "|".join(months[1:]) + ") (20[0-9]{2})", +m = re.match(r"# ([0-9][0-9]+)\. Plenum .+ ([0-9]{1,2})\. (" + + "|".join(months[1:]) + + ") (20[0-9]{2})", clipboard) if not m: print("Error: Überschrift nicht erkannt.", file=sys.stderr) @@ -52,5 +75,5 @@ links = "[⇐ vorheriges Plenum]({}) | [nächstes Plenum ⇒]({})".format(earlie markdown = "{}\n\n{}".format(links, clipboard) output = f"\n\n{markdown}" replaced = output.replace("[x]", "").replace("[ ]", "") -subprocess.run(["xclip", "-in", "-selection", "clipboard"], input=replaced.encode()) +set_clipboard(replaced) print("Dokuwiki-Code kopiert.")