Last active
October 19, 2022 07:18
-
-
Save EKami/d663a9ee56e782ad8741dab36e10efa0 to your computer and use it in GitHub Desktop.
Open and close terminator on Gnome 3 wayland
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://superuser.com/questions/142945/bash-command-to-focus-a-specific-window/1627429#1627429 | |
# To use, set a shortcut in Gnome like this: bash -c '/home/user/launch_focus_min_wayland.sh terminator' | |
# To check the available function names, do ALT + F2 and type "lg" | |
app=$1 | |
if [[ $app == terminator ]]; then | |
process_name=/usr/bin/terminator | |
else | |
process_name=$app | |
fi | |
#pid=$(pidof $process_name) # pidof didn't work for terminator | |
pid=$(pgrep -f $process_name) | |
shell_name='/bin/bash' # Since it's bash that started it | |
# If it isn't launched, then launch | |
if [ -z $pid ]; then | |
$app | |
else | |
# If it is launched then check if it is focused | |
foc=$(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_wm_class()" \ | |
| cut -d'"' -f 2) | |
if [[ $foc == 'terminator' ]]; then | |
# if it is focused, then minimize | |
gdbus call \ | |
--session \ | |
--dest org.gnome.Shell \ | |
--object-path /org/gnome/Shell \ | |
--method org.gnome.Shell.Eval \ | |
"var mw = global.get_window_actors().map(w=>w.meta_window).find(mw=>mw.get_title().includes('$shell_name')); | |
mw.minimize()" | |
else | |
# if it isn't focused then get focus | |
gdbus call \ | |
--session \ | |
--dest org.gnome.Shell \ | |
--object-path /org/gnome/Shell \ | |
--method org.gnome.Shell.Eval \ | |
"var mw = global.get_window_actors().map(w=>w.meta_window).find(mw=>mw.get_title().includes('$shell_name')); | |
mw.activate(0)" | |
fi | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For me,
.find(mw=>mw.get_title().includes('$shell_name'))
didn't work. Maybe because I use zsh instead of bash? Not sure. Regardless - I replaced it with.find(mw=>mw.get_wm_class().includes('terminator'))
and it works exactly as I hoped. Great script, thank you so much!