Desktop shortcut working for bash script but not the actual script?

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I need to create a script that I can bind to a keyboard shortcut.
The script opens an instance of mozilla if it is not open and if is it minimizes or maximises the window.
Kind of like drop down terminal.
The script is working when I open it from a desktop shortcut but if I open the script directly by clicking on it or macro it to a keyboard shortcut it doesn't work as expected. It only opens mozilla but doesn't minimize or maximize
#!/bin/bash
touch memory.txt
myvar="$( xdotool search Mozilla )"
status="$(grep [0-1] memory.txt)"
run=0
if [ $(grep -c [0-9] <<< $myvar) -gt 0 ]
then
pwd
else
(firefox &)
fi
if [ $status = 0 ]
then
$(xdotool windowminimize $myvar)
echo -n "1" > memory.txt
run=1
fi
if [ $status = 1 ] && [ $run -eq 0 ]
then
$(wmctrl -ia $myvar)
echo -n "0" > memory.txt
fi
exit
linux bash grep
add a comment |Â
up vote
1
down vote
favorite
I need to create a script that I can bind to a keyboard shortcut.
The script opens an instance of mozilla if it is not open and if is it minimizes or maximises the window.
Kind of like drop down terminal.
The script is working when I open it from a desktop shortcut but if I open the script directly by clicking on it or macro it to a keyboard shortcut it doesn't work as expected. It only opens mozilla but doesn't minimize or maximize
#!/bin/bash
touch memory.txt
myvar="$( xdotool search Mozilla )"
status="$(grep [0-1] memory.txt)"
run=0
if [ $(grep -c [0-9] <<< $myvar) -gt 0 ]
then
pwd
else
(firefox &)
fi
if [ $status = 0 ]
then
$(xdotool windowminimize $myvar)
echo -n "1" > memory.txt
run=1
fi
if [ $status = 1 ] && [ $run -eq 0 ]
then
$(wmctrl -ia $myvar)
echo -n "0" > memory.txt
fi
exit
linux bash grep
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I need to create a script that I can bind to a keyboard shortcut.
The script opens an instance of mozilla if it is not open and if is it minimizes or maximises the window.
Kind of like drop down terminal.
The script is working when I open it from a desktop shortcut but if I open the script directly by clicking on it or macro it to a keyboard shortcut it doesn't work as expected. It only opens mozilla but doesn't minimize or maximize
#!/bin/bash
touch memory.txt
myvar="$( xdotool search Mozilla )"
status="$(grep [0-1] memory.txt)"
run=0
if [ $(grep -c [0-9] <<< $myvar) -gt 0 ]
then
pwd
else
(firefox &)
fi
if [ $status = 0 ]
then
$(xdotool windowminimize $myvar)
echo -n "1" > memory.txt
run=1
fi
if [ $status = 1 ] && [ $run -eq 0 ]
then
$(wmctrl -ia $myvar)
echo -n "0" > memory.txt
fi
exit
linux bash grep
I need to create a script that I can bind to a keyboard shortcut.
The script opens an instance of mozilla if it is not open and if is it minimizes or maximises the window.
Kind of like drop down terminal.
The script is working when I open it from a desktop shortcut but if I open the script directly by clicking on it or macro it to a keyboard shortcut it doesn't work as expected. It only opens mozilla but doesn't minimize or maximize
#!/bin/bash
touch memory.txt
myvar="$( xdotool search Mozilla )"
status="$(grep [0-1] memory.txt)"
run=0
if [ $(grep -c [0-9] <<< $myvar) -gt 0 ]
then
pwd
else
(firefox &)
fi
if [ $status = 0 ]
then
$(xdotool windowminimize $myvar)
echo -n "1" > memory.txt
run=1
fi
if [ $status = 1 ] && [ $run -eq 0 ]
then
$(wmctrl -ia $myvar)
echo -n "0" > memory.txt
fi
exit
linux bash grep
linux bash grep
edited Aug 8 at 23:33
Rui F Ribeiro
36.5k1271116
36.5k1271116
asked Aug 8 at 23:26
Carter Apas
61
61
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
- What Desktop Environment are you using?
- How are you defining the keybinding? Through a script or gui or cli tool?
Regarding your script, be sure to define the FULL PATH of your script in the shortcut manager. Do not use ~ because it will not be interpreted by the graphical shell. Also, be sure to set the script to executable.
Here is a script that I use to accomplish the same thing you are after: (I use it for a different application, and so I changed the code below to represent "firefox" in order to match your question.)
Note: I am using GNOME 3.28.2 and xdotool 3.20160805.1
#!/bin/bash
wid=$(xdotool search --onlyvisible --name 'firefox')
if test "$wid" = "" ; then exec firefox &
fi
actual=$(xdotool getactivewindow)
if test $wid = $actual ; then xdotool windowminimize $wid
else xdotool windowactivate $wid
fi
##EOF
I'm using the newest version of xubuntu. I'm accessing the script through the default keyboard manager. For me your code only slightly works it open mozilla and minimizes it but when accessed the third time it doesn't maximize it creates a new instance. I believe my code works it just doesn't like being accessed through the keybind or when executed but for some reason a desktop shortcut to it works. Thanks for the fast response.
â Carter Apas
Aug 10 at 2:06
Check to see that xdotool is returning a valid ID and storing to the variable $wid. If there is no ID, then the "test" will fail and a new instance of the application will open as you described.
â Eminent
Aug 10 at 22:54
@CarterApas Regarding your script, be sure to define the FULL PATH of your script in the shortcut manager. Do not use "~" because it will not be interpreted by the graphical shell.
â Eminent
Aug 10 at 23:15
I think the problem with your script is in the first line. It only searches for visible firefox applications. If an application is not visible, which it will be when minimized, it will execute a firefox instance. The full path thing didn't work. Any ideas for the desktop shortcut issue apart from those pointed out?
â Carter Apas
Aug 13 at 3:40
I ended up getting it to work by making a bash script that opened the first script, and then linking with keyboard commands Thanks for help
â Carter Apas
Aug 14 at 2:11
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
- What Desktop Environment are you using?
- How are you defining the keybinding? Through a script or gui or cli tool?
Regarding your script, be sure to define the FULL PATH of your script in the shortcut manager. Do not use ~ because it will not be interpreted by the graphical shell. Also, be sure to set the script to executable.
Here is a script that I use to accomplish the same thing you are after: (I use it for a different application, and so I changed the code below to represent "firefox" in order to match your question.)
Note: I am using GNOME 3.28.2 and xdotool 3.20160805.1
#!/bin/bash
wid=$(xdotool search --onlyvisible --name 'firefox')
if test "$wid" = "" ; then exec firefox &
fi
actual=$(xdotool getactivewindow)
if test $wid = $actual ; then xdotool windowminimize $wid
else xdotool windowactivate $wid
fi
##EOF
I'm using the newest version of xubuntu. I'm accessing the script through the default keyboard manager. For me your code only slightly works it open mozilla and minimizes it but when accessed the third time it doesn't maximize it creates a new instance. I believe my code works it just doesn't like being accessed through the keybind or when executed but for some reason a desktop shortcut to it works. Thanks for the fast response.
â Carter Apas
Aug 10 at 2:06
Check to see that xdotool is returning a valid ID and storing to the variable $wid. If there is no ID, then the "test" will fail and a new instance of the application will open as you described.
â Eminent
Aug 10 at 22:54
@CarterApas Regarding your script, be sure to define the FULL PATH of your script in the shortcut manager. Do not use "~" because it will not be interpreted by the graphical shell.
â Eminent
Aug 10 at 23:15
I think the problem with your script is in the first line. It only searches for visible firefox applications. If an application is not visible, which it will be when minimized, it will execute a firefox instance. The full path thing didn't work. Any ideas for the desktop shortcut issue apart from those pointed out?
â Carter Apas
Aug 13 at 3:40
I ended up getting it to work by making a bash script that opened the first script, and then linking with keyboard commands Thanks for help
â Carter Apas
Aug 14 at 2:11
add a comment |Â
up vote
1
down vote
- What Desktop Environment are you using?
- How are you defining the keybinding? Through a script or gui or cli tool?
Regarding your script, be sure to define the FULL PATH of your script in the shortcut manager. Do not use ~ because it will not be interpreted by the graphical shell. Also, be sure to set the script to executable.
Here is a script that I use to accomplish the same thing you are after: (I use it for a different application, and so I changed the code below to represent "firefox" in order to match your question.)
Note: I am using GNOME 3.28.2 and xdotool 3.20160805.1
#!/bin/bash
wid=$(xdotool search --onlyvisible --name 'firefox')
if test "$wid" = "" ; then exec firefox &
fi
actual=$(xdotool getactivewindow)
if test $wid = $actual ; then xdotool windowminimize $wid
else xdotool windowactivate $wid
fi
##EOF
I'm using the newest version of xubuntu. I'm accessing the script through the default keyboard manager. For me your code only slightly works it open mozilla and minimizes it but when accessed the third time it doesn't maximize it creates a new instance. I believe my code works it just doesn't like being accessed through the keybind or when executed but for some reason a desktop shortcut to it works. Thanks for the fast response.
â Carter Apas
Aug 10 at 2:06
Check to see that xdotool is returning a valid ID and storing to the variable $wid. If there is no ID, then the "test" will fail and a new instance of the application will open as you described.
â Eminent
Aug 10 at 22:54
@CarterApas Regarding your script, be sure to define the FULL PATH of your script in the shortcut manager. Do not use "~" because it will not be interpreted by the graphical shell.
â Eminent
Aug 10 at 23:15
I think the problem with your script is in the first line. It only searches for visible firefox applications. If an application is not visible, which it will be when minimized, it will execute a firefox instance. The full path thing didn't work. Any ideas for the desktop shortcut issue apart from those pointed out?
â Carter Apas
Aug 13 at 3:40
I ended up getting it to work by making a bash script that opened the first script, and then linking with keyboard commands Thanks for help
â Carter Apas
Aug 14 at 2:11
add a comment |Â
up vote
1
down vote
up vote
1
down vote
- What Desktop Environment are you using?
- How are you defining the keybinding? Through a script or gui or cli tool?
Regarding your script, be sure to define the FULL PATH of your script in the shortcut manager. Do not use ~ because it will not be interpreted by the graphical shell. Also, be sure to set the script to executable.
Here is a script that I use to accomplish the same thing you are after: (I use it for a different application, and so I changed the code below to represent "firefox" in order to match your question.)
Note: I am using GNOME 3.28.2 and xdotool 3.20160805.1
#!/bin/bash
wid=$(xdotool search --onlyvisible --name 'firefox')
if test "$wid" = "" ; then exec firefox &
fi
actual=$(xdotool getactivewindow)
if test $wid = $actual ; then xdotool windowminimize $wid
else xdotool windowactivate $wid
fi
##EOF
- What Desktop Environment are you using?
- How are you defining the keybinding? Through a script or gui or cli tool?
Regarding your script, be sure to define the FULL PATH of your script in the shortcut manager. Do not use ~ because it will not be interpreted by the graphical shell. Also, be sure to set the script to executable.
Here is a script that I use to accomplish the same thing you are after: (I use it for a different application, and so I changed the code below to represent "firefox" in order to match your question.)
Note: I am using GNOME 3.28.2 and xdotool 3.20160805.1
#!/bin/bash
wid=$(xdotool search --onlyvisible --name 'firefox')
if test "$wid" = "" ; then exec firefox &
fi
actual=$(xdotool getactivewindow)
if test $wid = $actual ; then xdotool windowminimize $wid
else xdotool windowactivate $wid
fi
##EOF
edited Aug 10 at 23:17
answered Aug 9 at 0:49
Eminent
112
112
I'm using the newest version of xubuntu. I'm accessing the script through the default keyboard manager. For me your code only slightly works it open mozilla and minimizes it but when accessed the third time it doesn't maximize it creates a new instance. I believe my code works it just doesn't like being accessed through the keybind or when executed but for some reason a desktop shortcut to it works. Thanks for the fast response.
â Carter Apas
Aug 10 at 2:06
Check to see that xdotool is returning a valid ID and storing to the variable $wid. If there is no ID, then the "test" will fail and a new instance of the application will open as you described.
â Eminent
Aug 10 at 22:54
@CarterApas Regarding your script, be sure to define the FULL PATH of your script in the shortcut manager. Do not use "~" because it will not be interpreted by the graphical shell.
â Eminent
Aug 10 at 23:15
I think the problem with your script is in the first line. It only searches for visible firefox applications. If an application is not visible, which it will be when minimized, it will execute a firefox instance. The full path thing didn't work. Any ideas for the desktop shortcut issue apart from those pointed out?
â Carter Apas
Aug 13 at 3:40
I ended up getting it to work by making a bash script that opened the first script, and then linking with keyboard commands Thanks for help
â Carter Apas
Aug 14 at 2:11
add a comment |Â
I'm using the newest version of xubuntu. I'm accessing the script through the default keyboard manager. For me your code only slightly works it open mozilla and minimizes it but when accessed the third time it doesn't maximize it creates a new instance. I believe my code works it just doesn't like being accessed through the keybind or when executed but for some reason a desktop shortcut to it works. Thanks for the fast response.
â Carter Apas
Aug 10 at 2:06
Check to see that xdotool is returning a valid ID and storing to the variable $wid. If there is no ID, then the "test" will fail and a new instance of the application will open as you described.
â Eminent
Aug 10 at 22:54
@CarterApas Regarding your script, be sure to define the FULL PATH of your script in the shortcut manager. Do not use "~" because it will not be interpreted by the graphical shell.
â Eminent
Aug 10 at 23:15
I think the problem with your script is in the first line. It only searches for visible firefox applications. If an application is not visible, which it will be when minimized, it will execute a firefox instance. The full path thing didn't work. Any ideas for the desktop shortcut issue apart from those pointed out?
â Carter Apas
Aug 13 at 3:40
I ended up getting it to work by making a bash script that opened the first script, and then linking with keyboard commands Thanks for help
â Carter Apas
Aug 14 at 2:11
I'm using the newest version of xubuntu. I'm accessing the script through the default keyboard manager. For me your code only slightly works it open mozilla and minimizes it but when accessed the third time it doesn't maximize it creates a new instance. I believe my code works it just doesn't like being accessed through the keybind or when executed but for some reason a desktop shortcut to it works. Thanks for the fast response.
â Carter Apas
Aug 10 at 2:06
I'm using the newest version of xubuntu. I'm accessing the script through the default keyboard manager. For me your code only slightly works it open mozilla and minimizes it but when accessed the third time it doesn't maximize it creates a new instance. I believe my code works it just doesn't like being accessed through the keybind or when executed but for some reason a desktop shortcut to it works. Thanks for the fast response.
â Carter Apas
Aug 10 at 2:06
Check to see that xdotool is returning a valid ID and storing to the variable $wid. If there is no ID, then the "test" will fail and a new instance of the application will open as you described.
â Eminent
Aug 10 at 22:54
Check to see that xdotool is returning a valid ID and storing to the variable $wid. If there is no ID, then the "test" will fail and a new instance of the application will open as you described.
â Eminent
Aug 10 at 22:54
@CarterApas Regarding your script, be sure to define the FULL PATH of your script in the shortcut manager. Do not use "~" because it will not be interpreted by the graphical shell.
â Eminent
Aug 10 at 23:15
@CarterApas Regarding your script, be sure to define the FULL PATH of your script in the shortcut manager. Do not use "~" because it will not be interpreted by the graphical shell.
â Eminent
Aug 10 at 23:15
I think the problem with your script is in the first line. It only searches for visible firefox applications. If an application is not visible, which it will be when minimized, it will execute a firefox instance. The full path thing didn't work. Any ideas for the desktop shortcut issue apart from those pointed out?
â Carter Apas
Aug 13 at 3:40
I think the problem with your script is in the first line. It only searches for visible firefox applications. If an application is not visible, which it will be when minimized, it will execute a firefox instance. The full path thing didn't work. Any ideas for the desktop shortcut issue apart from those pointed out?
â Carter Apas
Aug 13 at 3:40
I ended up getting it to work by making a bash script that opened the first script, and then linking with keyboard commands Thanks for help
â Carter Apas
Aug 14 at 2:11
I ended up getting it to work by making a bash script that opened the first script, and then linking with keyboard commands Thanks for help
â Carter Apas
Aug 14 at 2:11
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
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%2funix.stackexchange.com%2fquestions%2f461403%2fdesktop-shortcut-working-for-bash-script-but-not-the-actual-script%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
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');
);
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');
);
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