I would like to create a keyboard shortcut that will open a new terminal window only if none exists on the current desktop. Otherwise, the currently existing one will be focused. I just upgraded from Fedora 24 to Fedora 25. Before upgrading, I had the following script bound to ctrl-alt-t:

desktop="$(xdotool get_desktop)" # Get number of current desktop

#Check if there is an open terminal on the current desktop. 
output="$(xdotool search --onlyvisible --class --desktop $desktop gnome-terminal)" 

if [[ -n "$output" ]] 
then xdotool windowactivate $output #If there is, then move focus to it. 
else gnome-terminal &  #Otherwise, open a new terminal. 

However, it seems that the update has broken the script, and it no longer runs properly; a new terminal is always opened, regardless of the presence of an existing one. As a test, I tried running this one liner desktop="$(xdotool get_desktop)" && for i in $(xdotool search --desktop $desktop --class ".*"); do xdotool getwindowname $i; done. Unsurprisingly, its output never includes the name of an existing terminal window. It seems that the problem is that xdotool no longer recognizes the gnome-terminal in Fedora 25, and as a result the above script will always create a new terminal.

EDIT: Also, running xdotool getwindowfocus getwindowname in terminal returns:

xdo_get_focused_window_sane failed (code=1)
xdo_focus_window reported an error

So it really seems that xdotool can no longer recognize gnome-terminal

  • This kind of stuff is better handled via gnome-shell extensions imo, see this related (almost duplicate) question... – don_crissti Jul 21 '17 at 19:37
  • Note, you are probably using gnome with wayland, which does not support xdotool. You can switch to X11 gnome, but this option will probably be removed in later releases. – meuh Jul 24 '17 at 15:35
  • @meuh Yup, switching to "Gnome with Xorg" did the trick. – FabulousGlobe Jul 25 '17 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.