restore legacy, include shorcut scripts
This commit is contained in:
85
dmapp/dmos/SETUP-KEYBOARD-SHORTCUTS.md
Normal file
85
dmapp/dmos/SETUP-KEYBOARD-SHORTCUTS.md
Normal file
@@ -0,0 +1,85 @@
|
||||
# Date/Time Clipboard Shortcuts Setup
|
||||
|
||||
This replaces espanso with a cleaner clipboard-based solution that won't trigger "Updated keyboard layout" notifications.
|
||||
|
||||
## How It Works
|
||||
|
||||
Instead of text expansion, keyboard shortcuts copy the formatted date/time to clipboard. You then paste with `Ctrl+V`.
|
||||
|
||||
## Available Formats
|
||||
|
||||
- **wd**: ISO week.day (e.g., `52.4`)
|
||||
- **3t**: 360-time division (e.g., `331`)
|
||||
- **uid**: Random UUID 8 chars (e.g., `a8b9bf0a`)
|
||||
|
||||
## GNOME Keyboard Shortcuts Setup
|
||||
|
||||
1. Open Settings → Keyboard → Keyboard Shortcuts (or run: `gnome-control-center keyboard`)
|
||||
|
||||
2. Scroll to bottom and click "+ Add Custom Shortcut"
|
||||
|
||||
3. Add three shortcuts:
|
||||
|
||||
### Shortcut 1: Week Day
|
||||
- **Name**: `Copy Week.Day`
|
||||
- **Command**: `/home/mariano/wdir/dm/dmapp/dmos/datetime-clipboard.py wd`
|
||||
- **Shortcut**: `Ctrl+Super+W`
|
||||
|
||||
### Shortcut 2: 360-Time
|
||||
- **Name**: `Copy 360-Time`
|
||||
- **Command**: `/home/mariano/wdir/dm/dmapp/dmos/datetime-clipboard.py 3t`
|
||||
- **Shortcut**: `Ctrl+Super+T`
|
||||
|
||||
### Shortcut 3: UUID
|
||||
- **Name**: `Copy UUID`
|
||||
- **Command**: `/home/mariano/wdir/dm/dmapp/dmos/datetime-clipboard.py uid`
|
||||
- **Shortcut**: `Ctrl+Super+U`
|
||||
|
||||
## Usage
|
||||
|
||||
1. Press the keyboard shortcut (e.g., `Ctrl+Super+W`)
|
||||
2. Paste with `Ctrl+V` wherever you need it
|
||||
|
||||
## Advantages Over Espanso
|
||||
|
||||
- No keyboard layout notifications
|
||||
- Works reliably on Wayland
|
||||
- Simpler architecture (no daemon running)
|
||||
- More control over when to paste
|
||||
- Works in password fields and other protected inputs
|
||||
|
||||
## Removing Espanso (Optional)
|
||||
|
||||
If you want to fully switch away from espanso:
|
||||
|
||||
```bash
|
||||
# Stop espanso service
|
||||
espanso stop
|
||||
|
||||
# Disable autostart
|
||||
espanso service unregister
|
||||
|
||||
# Uninstall (if desired)
|
||||
# sudo apt remove espanso # or however you installed it
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
# Test each format
|
||||
/home/mariano/wdir/dm/dmapp/dmos/datetime-clipboard.py wd
|
||||
/home/mariano/wdir/dm/dmapp/dmos/datetime-clipboard.py 3t
|
||||
/home/mariano/wdir/dm/dmapp/dmos/datetime-clipboard.py uid
|
||||
|
||||
# Then paste to verify clipboard contents
|
||||
```
|
||||
|
||||
## Cross-Platform Notes
|
||||
|
||||
This solution is part of the deskmeter cross-platform configuration effort:
|
||||
|
||||
- **Linux (Wayland/X11)**: Uses `wl-copy` or `xclip` for clipboard
|
||||
- **Windows**: Would require AutoHotkey or similar for global shortcuts
|
||||
- **macOS**: Would use `pbcopy` for clipboard
|
||||
|
||||
The core datetime logic is platform-independent Python. Only clipboard mechanism needs platform-specific handling.
|
||||
85
dmapp/dmos/cyclework.py
Normal file
85
dmapp/dmos/cyclework.py
Normal file
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
# Define the list of workspaces to cycle through
|
||||
WORKSPACES = [3, 6, 7, 8]
|
||||
|
||||
LAST_WS_FILE = "/tmp/lastws"
|
||||
|
||||
|
||||
def get_current_workspace():
|
||||
result = subprocess.run(["wmctrl", "-d"], capture_output=True, text=True)
|
||||
lines = result.stdout.splitlines()
|
||||
|
||||
for line in lines:
|
||||
if "*" in line: # The active workspace has a '*' symbol
|
||||
try:
|
||||
current_workspace = int(line.split()[0]) + 1
|
||||
print(f"Current workspace detected: {current_workspace}")
|
||||
return current_workspace
|
||||
except (IndexError, ValueError):
|
||||
print("Error parsing current workspace.")
|
||||
return None
|
||||
|
||||
print("No active workspace found.")
|
||||
return None
|
||||
|
||||
|
||||
def switch_to_workspace(workspace):
|
||||
print(f"Switching to workspace {workspace}")
|
||||
subprocess.run(["wmctrl", "-s", str(workspace - 1)])
|
||||
save_last_used_workspace(workspace)
|
||||
|
||||
|
||||
def save_last_used_workspace(workspace):
|
||||
with open(LAST_WS_FILE, "w") as f:
|
||||
f.write(str(workspace))
|
||||
|
||||
|
||||
def get_last_used_workspace():
|
||||
if os.path.exists(LAST_WS_FILE):
|
||||
with open(LAST_WS_FILE, "r") as f:
|
||||
try:
|
||||
return int(f.read().strip())
|
||||
except ValueError:
|
||||
return WORKSPACES[0]
|
||||
return WORKSPACES[0]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
if len(sys.argv) < 2 or sys.argv[1] not in ["up", "down", "current"]:
|
||||
print("Usage: python cyclework.py [up|down|current]")
|
||||
sys.exit(1)
|
||||
|
||||
direction = sys.argv[1]
|
||||
current = get_current_workspace()
|
||||
|
||||
if current is None:
|
||||
sys.exit(1)
|
||||
|
||||
if direction == "current":
|
||||
if current in WORKSPACES:
|
||||
print("Already in a workspace in the cycle.")
|
||||
sys.exit(0)
|
||||
|
||||
last_used = get_last_used_workspace()
|
||||
print(f"Switching to last used workspace in cycle: {last_used}")
|
||||
switch_to_workspace(last_used)
|
||||
sys.exit(0)
|
||||
|
||||
try:
|
||||
index = WORKSPACES.index(current)
|
||||
except ValueError:
|
||||
print("Current workspace is not in the list.")
|
||||
sys.exit(1)
|
||||
|
||||
if direction == "up":
|
||||
index = (index + 1) % len(WORKSPACES)
|
||||
else: # direction == 'down'
|
||||
index = (index - 1) % len(WORKSPACES)
|
||||
|
||||
next_workspace = WORKSPACES[index]
|
||||
switch_to_workspace(next_workspace)
|
||||
76
dmapp/dmos/datetime-clipboard.py
Normal file
76
dmapp/dmos/datetime-clipboard.py
Normal file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Date/time clipboard utility for GNOME keyboard shortcuts.
|
||||
Copies various date/time formats to clipboard for quick pasting.
|
||||
|
||||
Usage:
|
||||
datetime-clipboard.py wd # ISO week.day (e.g., 51.2)
|
||||
datetime-clipboard.py 3t # 360-time format (0-359)
|
||||
datetime-clipboard.py uid # UUID first 8 chars
|
||||
"""
|
||||
import sys
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
|
||||
def copy_to_clipboard(text):
|
||||
"""Copy text to clipboard using wl-copy (Wayland) or xclip (X11) as fallback."""
|
||||
try:
|
||||
# Try wl-copy first (Wayland)
|
||||
subprocess.run(['wl-copy'], input=text.encode(), check=True)
|
||||
except FileNotFoundError:
|
||||
# Fallback to xclip (X11)
|
||||
try:
|
||||
subprocess.run(['xclip', '-selection', 'clipboard'],
|
||||
input=text.encode(), check=True)
|
||||
except FileNotFoundError:
|
||||
print("Error: Neither wl-copy nor xclip found. Install wl-clipboard or xclip.",
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def get_weekday():
|
||||
"""ISO week.day format (e.g., 51.2)"""
|
||||
ywd = datetime.now().isocalendar()
|
||||
return f"{ywd[1]}.{ywd[2]}"
|
||||
|
||||
|
||||
def get_360time():
|
||||
"""Day divided into 360 parts (0-359)"""
|
||||
t = datetime.now()
|
||||
return str((t.hour * 60 + t.minute) // (1440 // 360))
|
||||
|
||||
|
||||
def get_uid():
|
||||
"""First 8 characters of UUID"""
|
||||
return str(uuid.uuid4())[:8]
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print(__doc__)
|
||||
sys.exit(1)
|
||||
|
||||
format_type = sys.argv[1].lower()
|
||||
|
||||
formatters = {
|
||||
'wd': get_weekday,
|
||||
'3t': get_360time,
|
||||
'uid': get_uid,
|
||||
}
|
||||
|
||||
if format_type not in formatters:
|
||||
print(f"Unknown format: {format_type}")
|
||||
print(__doc__)
|
||||
sys.exit(1)
|
||||
|
||||
text = formatters[format_type]()
|
||||
copy_to_clipboard(text)
|
||||
|
||||
# Optional: print to stdout for verification
|
||||
print(f"Copied to clipboard: {text}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user