0

Simple question. Under custom keyboard shortcuts I have tried xterm ~/Desktop/folder/subfolber/textfile but that does not work.

It's my understanding that keyboard shortcuts are terminal commands. When I enter the above in terminal nothing happens, so I probably have the wrong directory. But if I type sh ~/Desktop/folder/subfolber/textfile in terminal I can run the text file, but then this shortcut does not work if I try and add it via keyboard options.

Any clarification is appreciated.

Sam C
  • 23
  • What do you mean by "run a text file"? Is it a bash script ? If you want to open a text file, you can do it with a text editor, like gedit. gedit /path/to/your/file – mxdsp Oct 12 '15 at 19:42
  • 1
    No clue what you are trying to schieve, but you cannot use ~ in a .desktop file. Use absolute paths instead. – Jacob Vlijm Oct 12 '15 at 19:53
  • If I type sh ~/Desktop/folder/subfolber/textfile in terminal – Sam C Oct 13 '15 at 20:08
  • The file is a shell script. I just realized this, but all the "sh" terminal is an abbreviation for shell. When Jacob mentions absolute paths I assume that it should be /home/[user name]/Documents/whatever instead of ~/Documents? – Sam C Oct 13 '15 at 20:23

1 Answers1

0

Keyboard shortcuts are commands but they belong to daemons, such as gnome-settings-daemon or unity-settings-daemon. In case of X-server in general, regardless of which GUI you use, shortcuts may be altered with xbindkeys app.

However, in your specific case, what you really need to make xterm open and run a script is the following:

  1. Go to Settings -> Keyboard -> Shortcuts -> Custom;
  2. Add a new shorcut; tell it to run xterm with full path to the script , e.g., xterm -hold -e /home/user/bin/myScript.sh
  3. Assign keypress to it.

Note: script must be made executable with chmod 755 /path/to/script.sh

Here's my example:

Script in /home/serg/testScript.sh

#!/bin/bash
printf "This was a triumph\nI'm making a note here, huge success"
df
date

Shortcut setup

enter image description here

Output

enter image description here

Check out my other answers that assign scripts to shortcuts:

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
  • Don't forget to leave an upvote if you like my answer ;) – Sergiy Kolodyazhnyy Oct 14 '15 at 07:08
  • Really a fantastic answer. This is why I like this site. – Sam C Oct 15 '15 at 19:45
  • Arg... well I thought it was working. I can execute the script from a shortcut now, and can use printf to display a message in xterm, but oddly enough it don't open the program. My script looks like #!/bin/bash printf "Testing 123" sh ~/Desktop/java/jgrasp/bin/jgrasp' The odd part is if I enter just 'sh ~/Desktop/java/jgrasp/bin/jgrasp' into xterm it will execute correctly. – Sam C Oct 15 '15 at 19:51
  • Does it work if you give it full path instead if using ~ ? – Sergiy Kolodyazhnyy Oct 15 '15 at 21:09
  • Still no luck with the full path. Does it matter in which directory the script is? I mean as long as the shortcut has the correct path. – Sam C Oct 15 '15 at 22:34
  • OK, so I downloaded the zip file with jgrasp, added the same command you had and it works fine for me. The /home/user/jgrasp/bin/jgrasp is a script , so you may want to check the permissions on that file with ls -l. Also you don't need sh part in the command, giving the path to file itself will do; otherwise you're creating one too many processes – Sergiy Kolodyazhnyy Oct 16 '15 at 00:58