How to get the active window name in Javascript?

Hi everyone,

I’ve installed a quite useful extension that displays a cheat sheet (Shortcuts - GNOME Shell Extensions).

I’d like to modify it, so it displays a different cheat sheet according to the active window (e.g. a Firefox cheat sheet if I currently work on Firefox, a Nautilus cheat sheet if I currently use Nautilus, and so on).

It should be rather trivial to implement, but I am struggling to find the javascript method to retrieve the active window name. Does anybody know how to do that ?

It’s better to use the window tracker to identify applications than to try window matching yourself based on the window name. Something like this should work:

Shell.WindowTracker.get_default().get_window_app(global.display.focus_window)?.id
2 Likes

Great, perfect ! Thanks !

Shell.WindowTracker.get_default().focus_app.id

is a bit more convenient.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.