How to create a shortcut to start, minimize and bring programs to the foreground
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
1
down vote
favorite
I just switched to Linux and I am setting up my laptop. In windows, I use an AutoHotkey shortcut, to do the following:
- Open "chrome" when it is not active.
- Minimize "chrome" when it in the foreground.
- Bring it to the foreground when the window is not active.
I use the following code in "Autokey" which works nicely but I would love it if I can do this with a simple bash script:
#AutoKey script to toggle any windowed application, Nautilus as the example. Requires xdotool and wmctrl.
import subprocess
command = 'wmctrl -lx'
output = system.exec_command(command, getOutput=True)
if 'google-chrome' in output:
winClass = window.get_active_class()
if winClass == 'google-chrome.Google-chrome':
system.exec_command("xdotool windowminimize $(xdotool getactivewindow)")
else:
system.exec_command("wmctrl -x -a google-chrome")
else:
system.exec_command("google-chrome")
#end script
Now I tried to translate this to bash code but I get stuck in checking if chrome is running in the foreground. I had the following pseudocode in mind but I can not find the right shell commands:
if chrome is not open
open chrome
else
if chrome is on foreground
minimize chrome
else
bring chrome to foreground
end
I tried to do obtain this behaviour in Linux by using a shell script in the Linux "shortcut" application. But up till now, I was not able to find a way to check if Google-chrome is in the foreground. I tried using the "xdotools" package but this doesn't seem to work:
if ($(xdotool search --name "Google Chrome") -eq $(xdotool getactivewindow))
xdotool windowminimize $(xdotool getactivewindow)
else
wmctrl -x -a google-chrome
end
Do you maybe have some tips on what is the best way to achieve this? I now have the following ingredients:
To open google-chrome I use:
google-chrome &
To minimize google-chrome I use:
xdotool windowminimize $(xdotool getactivewindow)
To maximize google-chrome I use:
wmctrl -x -a google-chrome
And I think I need to use something like this to check if chrome is on foreground:
wmctrl -lx
xdotool search --name "Google Chrome"
xdotool getactivewindow
enter code here
Thanks a lot in advance,
Greetings,
Rick,
System information:
Desktop: Hp Zbook G3 studio
Distributor ID: Ubuntu
Description: Ubuntu Bionic Beaver (development branch)
Release: 18.04
Codename: bionic
shortcut-keys shortcuts
add a comment |Â
up vote
1
down vote
favorite
I just switched to Linux and I am setting up my laptop. In windows, I use an AutoHotkey shortcut, to do the following:
- Open "chrome" when it is not active.
- Minimize "chrome" when it in the foreground.
- Bring it to the foreground when the window is not active.
I use the following code in "Autokey" which works nicely but I would love it if I can do this with a simple bash script:
#AutoKey script to toggle any windowed application, Nautilus as the example. Requires xdotool and wmctrl.
import subprocess
command = 'wmctrl -lx'
output = system.exec_command(command, getOutput=True)
if 'google-chrome' in output:
winClass = window.get_active_class()
if winClass == 'google-chrome.Google-chrome':
system.exec_command("xdotool windowminimize $(xdotool getactivewindow)")
else:
system.exec_command("wmctrl -x -a google-chrome")
else:
system.exec_command("google-chrome")
#end script
Now I tried to translate this to bash code but I get stuck in checking if chrome is running in the foreground. I had the following pseudocode in mind but I can not find the right shell commands:
if chrome is not open
open chrome
else
if chrome is on foreground
minimize chrome
else
bring chrome to foreground
end
I tried to do obtain this behaviour in Linux by using a shell script in the Linux "shortcut" application. But up till now, I was not able to find a way to check if Google-chrome is in the foreground. I tried using the "xdotools" package but this doesn't seem to work:
if ($(xdotool search --name "Google Chrome") -eq $(xdotool getactivewindow))
xdotool windowminimize $(xdotool getactivewindow)
else
wmctrl -x -a google-chrome
end
Do you maybe have some tips on what is the best way to achieve this? I now have the following ingredients:
To open google-chrome I use:
google-chrome &
To minimize google-chrome I use:
xdotool windowminimize $(xdotool getactivewindow)
To maximize google-chrome I use:
wmctrl -x -a google-chrome
And I think I need to use something like this to check if chrome is on foreground:
wmctrl -lx
xdotool search --name "Google Chrome"
xdotool getactivewindow
enter code here
Thanks a lot in advance,
Greetings,
Rick,
System information:
Desktop: Hp Zbook G3 studio
Distributor ID: Ubuntu
Description: Ubuntu Bionic Beaver (development branch)
Release: 18.04
Codename: bionic
shortcut-keys shortcuts
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I just switched to Linux and I am setting up my laptop. In windows, I use an AutoHotkey shortcut, to do the following:
- Open "chrome" when it is not active.
- Minimize "chrome" when it in the foreground.
- Bring it to the foreground when the window is not active.
I use the following code in "Autokey" which works nicely but I would love it if I can do this with a simple bash script:
#AutoKey script to toggle any windowed application, Nautilus as the example. Requires xdotool and wmctrl.
import subprocess
command = 'wmctrl -lx'
output = system.exec_command(command, getOutput=True)
if 'google-chrome' in output:
winClass = window.get_active_class()
if winClass == 'google-chrome.Google-chrome':
system.exec_command("xdotool windowminimize $(xdotool getactivewindow)")
else:
system.exec_command("wmctrl -x -a google-chrome")
else:
system.exec_command("google-chrome")
#end script
Now I tried to translate this to bash code but I get stuck in checking if chrome is running in the foreground. I had the following pseudocode in mind but I can not find the right shell commands:
if chrome is not open
open chrome
else
if chrome is on foreground
minimize chrome
else
bring chrome to foreground
end
I tried to do obtain this behaviour in Linux by using a shell script in the Linux "shortcut" application. But up till now, I was not able to find a way to check if Google-chrome is in the foreground. I tried using the "xdotools" package but this doesn't seem to work:
if ($(xdotool search --name "Google Chrome") -eq $(xdotool getactivewindow))
xdotool windowminimize $(xdotool getactivewindow)
else
wmctrl -x -a google-chrome
end
Do you maybe have some tips on what is the best way to achieve this? I now have the following ingredients:
To open google-chrome I use:
google-chrome &
To minimize google-chrome I use:
xdotool windowminimize $(xdotool getactivewindow)
To maximize google-chrome I use:
wmctrl -x -a google-chrome
And I think I need to use something like this to check if chrome is on foreground:
wmctrl -lx
xdotool search --name "Google Chrome"
xdotool getactivewindow
enter code here
Thanks a lot in advance,
Greetings,
Rick,
System information:
Desktop: Hp Zbook G3 studio
Distributor ID: Ubuntu
Description: Ubuntu Bionic Beaver (development branch)
Release: 18.04
Codename: bionic
shortcut-keys shortcuts
I just switched to Linux and I am setting up my laptop. In windows, I use an AutoHotkey shortcut, to do the following:
- Open "chrome" when it is not active.
- Minimize "chrome" when it in the foreground.
- Bring it to the foreground when the window is not active.
I use the following code in "Autokey" which works nicely but I would love it if I can do this with a simple bash script:
#AutoKey script to toggle any windowed application, Nautilus as the example. Requires xdotool and wmctrl.
import subprocess
command = 'wmctrl -lx'
output = system.exec_command(command, getOutput=True)
if 'google-chrome' in output:
winClass = window.get_active_class()
if winClass == 'google-chrome.Google-chrome':
system.exec_command("xdotool windowminimize $(xdotool getactivewindow)")
else:
system.exec_command("wmctrl -x -a google-chrome")
else:
system.exec_command("google-chrome")
#end script
Now I tried to translate this to bash code but I get stuck in checking if chrome is running in the foreground. I had the following pseudocode in mind but I can not find the right shell commands:
if chrome is not open
open chrome
else
if chrome is on foreground
minimize chrome
else
bring chrome to foreground
end
I tried to do obtain this behaviour in Linux by using a shell script in the Linux "shortcut" application. But up till now, I was not able to find a way to check if Google-chrome is in the foreground. I tried using the "xdotools" package but this doesn't seem to work:
if ($(xdotool search --name "Google Chrome") -eq $(xdotool getactivewindow))
xdotool windowminimize $(xdotool getactivewindow)
else
wmctrl -x -a google-chrome
end
Do you maybe have some tips on what is the best way to achieve this? I now have the following ingredients:
To open google-chrome I use:
google-chrome &
To minimize google-chrome I use:
xdotool windowminimize $(xdotool getactivewindow)
To maximize google-chrome I use:
wmctrl -x -a google-chrome
And I think I need to use something like this to check if chrome is on foreground:
wmctrl -lx
xdotool search --name "Google Chrome"
xdotool getactivewindow
enter code here
Thanks a lot in advance,
Greetings,
Rick,
System information:
Desktop: Hp Zbook G3 studio
Distributor ID: Ubuntu
Description: Ubuntu Bionic Beaver (development branch)
Release: 18.04
Codename: bionic
shortcut-keys shortcuts
edited Apr 29 at 13:44
asked Apr 26 at 20:10
![](https://lh4.googleusercontent.com/-xMiPgBYJ5p0/AAAAAAAAAAI/AAAAAAAADlU/e7aKw2WX6Ec/photo.jpg?sz=32)
![](https://lh4.googleusercontent.com/-xMiPgBYJ5p0/AAAAAAAAAAI/AAAAAAAADlU/e7aKw2WX6Ec/photo.jpg?sz=32)
arcety
316
316
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
I received the answer to my question from a user on another forum.
#!/bin/bash
chromefocus=$(xdotool getwindowfocus getwindowname | grep -c "Google Chrome")
if [ "$chromefocus" -gt "0" ]; then
xdotool windowminimize $(xdotool getactivewindow)
else
wmctrl -xa "google-chrome.Google-chrome" || /usr/bin/google-chrome
fi
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I received the answer to my question from a user on another forum.
#!/bin/bash
chromefocus=$(xdotool getwindowfocus getwindowname | grep -c "Google Chrome")
if [ "$chromefocus" -gt "0" ]; then
xdotool windowminimize $(xdotool getactivewindow)
else
wmctrl -xa "google-chrome.Google-chrome" || /usr/bin/google-chrome
fi
add a comment |Â
up vote
1
down vote
accepted
I received the answer to my question from a user on another forum.
#!/bin/bash
chromefocus=$(xdotool getwindowfocus getwindowname | grep -c "Google Chrome")
if [ "$chromefocus" -gt "0" ]; then
xdotool windowminimize $(xdotool getactivewindow)
else
wmctrl -xa "google-chrome.Google-chrome" || /usr/bin/google-chrome
fi
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I received the answer to my question from a user on another forum.
#!/bin/bash
chromefocus=$(xdotool getwindowfocus getwindowname | grep -c "Google Chrome")
if [ "$chromefocus" -gt "0" ]; then
xdotool windowminimize $(xdotool getactivewindow)
else
wmctrl -xa "google-chrome.Google-chrome" || /usr/bin/google-chrome
fi
I received the answer to my question from a user on another forum.
#!/bin/bash
chromefocus=$(xdotool getwindowfocus getwindowname | grep -c "Google Chrome")
if [ "$chromefocus" -gt "0" ]; then
xdotool windowminimize $(xdotool getactivewindow)
else
wmctrl -xa "google-chrome.Google-chrome" || /usr/bin/google-chrome
fi
answered Apr 30 at 17:48
![](https://lh4.googleusercontent.com/-xMiPgBYJ5p0/AAAAAAAAAAI/AAAAAAAADlU/e7aKw2WX6Ec/photo.jpg?sz=32)
![](https://lh4.googleusercontent.com/-xMiPgBYJ5p0/AAAAAAAAAAI/AAAAAAAADlU/e7aKw2WX6Ec/photo.jpg?sz=32)
arcety
316
316
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1028527%2fhow-to-create-a-shortcut-to-start-minimize-and-bring-programs-to-the-foreground%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password