[Python] Clipboard2Markdown 剪藏MD


說明

這段 Python 程式碼會將剪貼簿內容儲存為 Markdown 檔案,檔名含時間戳記,並在桌面建立檔案後,用記事本開啟它。適合快速保存臨時筆記或片段文字。

程式碼

import pyperclip
import os
import time
import subprocess

clipboard_content = pyperclip.paste()
desktop = os.path.join(os.path.expanduser("~"), "Desktop")
timestamp = time.strftime("%Y%m%d_%H%M%S")
file_path = os.path.join(desktop, f"文字錄_{timestamp}.md")

with open(file_path, "w", encoding="utf-8") as f:
    f.write(clipboard_content)

# 用 start 指令讓記事本獨立執行,主程式可結束
subprocess.run(["start", "notepad.exe", file_path], shell=True)

小泉

喜愛用文字說明自己眼中所見的一切

較新的 較舊

نموذج الاتصال