1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#!/usr/bin/env python3
"""
This script automatically enables Discord Rich Presence whenever darktable is running and clears it when darktable closes.
How to Run:
Open a terminal where this script is
Install the required python package:
pip install psutil pypresence
Run the script:
python darktable_rpc.py
Keep the terminal running when you launch darktable, your Discord status will update automatically.
"""
import time
import psutil
from pypresence import Presence
# Discord Application ID
CLIENT_ID = '1437906050467631326'
PROCESS_NAMES = ['darktable', 'darktable.exe', 'darktable-bin']
def is_darktable_running():
for proc in psutil.process_iter(['name']):
try:
if proc.info['name'] in PROCESS_NAMES:
return True
except (psutil.NoSuchProcess, psutil.AccessDenied):
continue
return False
def main():
print("darktable Discord Rich Presence")
print("Waiting for darktable to start...")
rpc = None
presence_active = False
start_time = None
try:
while True:
darktable_running = is_darktable_running()
# darktable just started
if darktable_running and not presence_active:
print("darktable detected, activating Discord presence...")
try:
rpc = Presence(CLIENT_ID)
rpc.connect()
start_time = int(time.time())
rpc.update(
state="Photo editing",
details="darktable",
large_image="darktable_icon",
large_text="darktable - photography workflow",
start=start_time
)
presence_active = True
print("Discord presence active!")
except Exception as e:
print(f"Error connecting to Discord: {e}")
print("Make sure Discord is running.")
# darktable just closed
elif not darktable_running and presence_active:
print("darktable closed. Clearing Discord presence...")
try:
if rpc:
rpc.close()
rpc = None
except Exception as e:
print(f"Error closing Discord connection: {e}")
presence_active = False
start_time = None
print("Waiting for darktable to start again...")
time.sleep(5)
except KeyboardInterrupt:
if rpc and presence_active:
try:
rpc.close()
except:
pass
print("Discord Rich Presence stopped.")
if __name__ == "__main__":
main()
|