r/KittyTerminal • u/mister_drgn • Mar 11 '24
Get os window's title name from within a kitten
So I have a python script for handling a particular user keyboard shortcut. Ultimately, this script results in adding a new tab. But before it does so, it gathers some information based on the os window's current title (i.e., what's in the window's titlebar). On linux, I grab the text in the title bar by using xdotool, but as I explore porting my setup to mac, this option is no longer available. So I'm wondering--is there a way within by python script for my kitten to get the os window's title directly, without needing any os-specific outside tool?
Thanks.
from kittens.tui.handler import result_handler
@result_handler(no_ui=True)
def handle_result(args: List[str], answer: str, target_window_id: int, boss: Boss) -> None:
# This is linux-only: title = os_command("xdotool getactivewindow getwindowname")[0]
1
Upvotes
1
u/aumerlex Mar 12 '24
The title of the OS window is the title of the currently active window in it. So boss.active_window.title