GNOME3 keyboard shortcuts doesn't run my script

2

1

I have a home made script that takes a screenshot and uploads it to puush, and I have put the script in /usr/bin. If I open a terminal and write the name of the script it runs perfectly. I use Debian Unstable(Sid) with Gnome3.

What I am trying to do is to put the script on a keyboard shortcut or at least run it without open a terminal. I have tried to use the Alt+F2 to open a command prompt, but of some reason my script doesn't run even if I try to invoke it that way. Same thing if I put the script to a keyboard shortcut.
I have also looked at the permissions for the file, and everyone is allowed to read or run the script, and it's owned by root and is in the root group, just like other programs.

Link to the script

The goal is to run the homemade script using a keyboard shortcut, and using command prompt as a secondary option if keyboard shortcut doesn't work. I am stumped on what to do though.

Things tested so far:
Using whole path to run the script.
Open gnome-terminal and pass the script as a parameter "gnome-terminal -e script"
add #!/bin/bash in beginning of script

Wertilq

Posted 2013-09-17T08:39:38.577

Reputation: 121

Does your script have a shebang? – FSMaxB – 2013-09-18T07:32:12.953

Btw, you really should change the title of your question, because you know how to make a keyboard shortcut and the title makes one think you don't! – FSMaxB – 2013-09-18T07:55:09.517

@FSMaxB What is a shebang? Any suggestions for a better title? – Wertilq – 2013-09-18T12:38:30.187

A shebang is the '#!/bin/whatever-shell' at the beginning of the script. Have you tried calling the script by it's full path (/usr/bin/script) instead of just it's name? As to the title: for example "GNOME3 keyboard shortcut doesn't run script". – FSMaxB – 2013-09-18T16:06:22.260

@FSMaxB I have a feeling it DOES find the script, since it just immediately closes down the ALT+F2 prompt when I type it right. If I type wrong name of script, it says there is no such file. What shebang should I put in beginning of the script? – Wertilq – 2013-09-19T11:34:34.823

Normally the shebang is #!/bin/sh if it is a shell script, if it's python for example, it would most likely be #!/usr/bin/python . You should really try running it by the full path instead of just it's name and therefore relying on the PATH variable. – FSMaxB – 2013-09-19T14:34:59.403

@FSMaxB I tried running with full path, and that did not work, I will try with #!/bin/sh tomorrow. – Wertilq – 2013-09-19T15:13:48.077

@FSMaxB it have a #!/bin/bash – Wertilq – 2013-09-20T14:24:03.960

Then I have no further suggestions on what to do! – FSMaxB – 2013-09-20T18:10:18.353

@FSMaxB well I got it working, see my own answer to the question. – Wertilq – 2013-09-20T19:32:01.627

Answers

0

Problem solved. Apparently I had indentation on the #!/bin/bash, I removed that to ensure there was no white space, endlines or anything like that inbefore the #. The script now runs from Alt+F2, and also from keyboard shortcut, albeit a bit bad response time, and not every time I click.

Thanks @FSMaxB for making me look into more details about the shebang, and thanks to tbekolay for some solid tips.

Wertilq

Posted 2013-09-17T08:39:38.577

Reputation: 121

Great to hear that it's working now! – FSMaxB – 2013-09-21T09:36:48.780

3

The command prompt opened by Alt+F2 does not necessarily have the same $PATH as your login shell that executes in a terminal.

You can see the value of $PATH that gnome-shell with

strings /proc/`pidof gnome-shell`/environ | grep PATH

If /usr/bin isn't in that list, then you need to modify ~/.profile to include /usr/bin in $PATH`:

PATH="/usr/bin:$PATH"

Another issue is that Alt+F2 cannot launch bash or other shells. A way around this is to use Alt+F2 to launch gnome-terminal and run your script though that. So, after pressing Alt+F2, type in

gnome-terminal -e my-script.sh

This will have the unfortunate side effect of popping up a gnome-terminal window, which will close after executing the script.

It sounds like you might be better served with something like Guake, which allows you to drop down a full terminal at the push of a button (screenshots).

tbekolay

Posted 2013-09-17T08:39:38.577

Reputation: 141

/usr/bin was in that list. PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games – Wertilq – 2013-09-19T11:32:25.360

ALT+F2 finds the script, but fail to execute it I think. If I type the name of the script wrong, like call it jklgf, or puuush instead of puush, then it say there is no such file or directory. If I type it right, it just closes down the prompt immeditately – Wertilq – 2013-09-19T11:36:10.737

What does your script do? Alt+F2 is designed for launching graphical applications and quick access to folders. But it's not a full terminal emulator; if you type in echo "Hello world", for example, nothing will happen. echo "test" > /home/me/test.txt does nothing either. It's just not designed to be a terminal replacement. – tbekolay – 2013-09-19T13:51:55.213

There is a link to pastebin for the script in the question. – Wertilq – 2013-09-19T15:12:40.870

Ok, I see. Yeah, you can't run bash from Alt+F2. I've added some workarounds to my answer. – tbekolay – 2013-09-19T15:53:23.113

I tried doing the "gnome-terminal -e my-script.sh" it opens a terminal and instantcloses it, and the script is not run properly – Wertilq – 2013-09-20T14:19:18.033

I also tested all sorts of launch parameters, and tried full path, just name any many other things none of it worked. The terminal just instant closes – Wertilq – 2013-09-20T14:30:58.880