2

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

asked Sep 17, 2013 at 8:39
10
  • Does your script have a shebang? Commented Sep 18, 2013 at 7:32
  • 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! Commented Sep 18, 2013 at 7:55
  • @FSMaxB What is a shebang? Any suggestions for a better title? Commented Sep 18, 2013 at 12:38
  • 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". Commented Sep 18, 2013 at 16:06
  • @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? Commented Sep 19, 2013 at 11:34

2 Answers 2

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).

answered Sep 18, 2013 at 23:39
7
  • /usr/bin was in that list. PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games Commented Sep 19, 2013 at 11:32
  • 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 Commented Sep 19, 2013 at 11:36
  • 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. Commented Sep 19, 2013 at 13:51
  • There is a link to pastebin for the script in the question. Commented Sep 19, 2013 at 15:12
  • Ok, I see. Yeah, you can't run bash from Alt+F2. I've added some workarounds to my answer. Commented Sep 19, 2013 at 15:53
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.

answered Sep 20, 2013 at 15:13
1
  • Great to hear that it's working now! Commented Sep 21, 2013 at 9:36

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.