DraxCodes revised this gist . Go to revision
1 file changed, 35 insertions
Title.sh(file created)
| @@ -0,0 +1,35 @@ | |||
| 1 | + | #!/usr/bin/env bash | |
| 2 | + | ||
| 3 | + | get_active_window_title() { | |
| 4 | + | # 1. Check if running under X11 (or XWayland fallback context) | |
| 5 | + | if [ "$XDG_SESSION_TYPE" = "x11" ]; then | |
| 6 | + | xdotool getwindowfocus getwindowname 2>/dev/null | |
| 7 | + | return | |
| 8 | + | fi | |
| 9 | + | ||
| 10 | + | # 2. Check Wayland Compositors | |
| 11 | + | case "${XDG_CURRENT_DESKTOP,,}" in | |
| 12 | + | *gnome*) | |
| 13 | + | # GNOME doesn't expose a straightforward CLI tool for security reasons. | |
| 14 | + | # If you have the 'unrestricted' or 'unsafe-mode' enabled for DBus Eval: | |
| 15 | + | gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "global.get_window_actors().map(a => a.meta_window).find(w => w.has_focus()).get_title()" 2>/dev/null | sed "s/('//;s/',)//" | |
| 16 | + | ;; | |
| 17 | + | *sway*) | |
| 18 | + | # Sway/i3 native IPC | |
| 19 | + | swaymsg -t get_tree | jq -r '.. | try select(.focused == true).name' 2>/dev/null | |
| 20 | + | ;; | |
| 21 | + | *hyprland*) | |
| 22 | + | # Hyprland native IPC | |
| 23 | + | hyprctl activewindow -j | jq -r '.title' 2>/dev/null | |
| 24 | + | ;; | |
| 25 | + | *) | |
| 26 | + | echo "Unsupported or strictly sandboxed environment." | |
| 27 | + | return 1 | |
| 28 | + | ;; | |
| 29 | + | case | |
| 30 | + | } | |
| 31 | + | ||
| 32 | + | # Stream/Watch mode example (Uncomment if you want to poll it) | |
| 33 | + | # while true; do get_active_window_title; sleep 1; done | |
| 34 | + | ||
| 35 | + | get_active_window_title | |
Newer
Older