|# Single Command, runs 2 calls to gdbus to get the currently active Window from Gnome 3.x|
|# Escaped so you can copy and paste into terminal directly|
|gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval global.get_window_actors\(\)[`gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval global.get_window_actors\(\).findIndex\(a\=\>a.meta_window.has_focus\(\)===true\) | cut -d"'" -f 2`].get_meta_window\(\).get_wm_class\(\) | cut -d'"' -f 2|
|# Unescaped version, will not run|
|# Broken down into 2 commands.|
|# Call to Gnome to get the array location of the active Application|
|gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m \|
|org.gnome.Shell.Eval global.get_window_actors().findIndex(a=>a.meta_window.has_focus()===true) \|
|| cut -d"'" -f 2|
|# Replace the array number 2 with the one from the previous command and you will get the App Name of the actively focused Window|
|gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval \|
|| cut -d'"' -f 2|
Will also make note that this may be a similar alternative on how to do this under KDE.
Yea, I have noticed that the inner or 1st call can also fail if you're in a state between applications as the DE knows the new active window or app is not ready and yet the old one is already non-active so you are left with a 1st call that comes back with nothing. It could be written better to try and avoid that.
@RaghavRao You can probably work something out by looking at this thread, they limit alt+tab to only the apps on a particular active monitor - but considering they're able to limit the Windows via a filter for alt+tab.. I would think you might be able to modify the code in some way to simply activate a particular Window/App however you want, but I am not entirely sure.
You may be able to use d-feet or some app to help you dump/view the methods available as well.
For my own purpose I don't need to re-activate an app or window as my own app will only ever monitor the app the user has currently selected. Anything beyond that, for me, is not needed.
This was very helpful for me! Thank you!
I was easily able to write a second query identical to the first, substituting only