D
D
Daniel Reed2013-05-30 10:18:41
linux
Daniel Reed, 2013-05-30 10:18:41

Running a bash script with a hotkey?

The situation is as follows: there is Linux Mint, there is a script, you need to run the script by pressing "Ctrl + T". It starts once, does its job and turns off.
If interested, the script code

#!/bin/sh<br>
n=0<br>
clip=$(xsel -o)<br>
if  ; then<br>
  clip=$(wget -U "Mozilla/5.0" -qO - "http://translate.google.com/translate_a/t?client=t&text=$(echo $clip | sed "s/[\"'<>]//g; s/&/%26/g")&sl=auto&tl=ru" | sed 's/\[\[\[\"//' | cut -d \" -f 1)<br>
  notify-send "$clip" "en->ru"<br>
  n=1<br>
elif  ; then<br>
  clip=$(wget -U "Mozilla/5.0" -qO - "http://translate.google.com/translate_a/t?client=t&text=$(echo $clip | sed "s/[\"'<>]//g; s/&/%26/g")&sl=auto&tl=en" | sed 's/\[\[\[\"//' | cut -d \" -f 1)<br>
  notify-send "$clip" "ru->en"<br>
  n=1<br>
elif  ; then<br>
  clip=$(echo $clip | sed 's/\#//g')<br>
  notify-send "#$clip" "#$clip"<br>
  n=1<br>
fi<br>
if  ; then<br>
  clip=$(wget -U "Mozilla/5.0" -qO - "http://translate.google.com/translate_a/t?client=t&text=$(echo $clip | sed "s/[\"'<>]//g; s/&/%26/g")&sl=auto&tl=ru" | sed 's/\[\[\[\"//' | cut -d \" -f 1)<br>
  notify-send "$clip" "*->ru"<br>
fi<br>

It is called, for example, ".translate.sh". Execution rights to the script are given "sudo chmod +x .translate.sh". In the settings "Keyboard shortcuts", I created a new bind, the command "./.translate.sh" the combination "Ctrl + T".
Does not work, displays a window with the text "An error occurred while trying to run the command (./.translate.sh) that
is bound to the combination (Primary t)"
Tried another combination, tried "sh .translate.sh", nothing helped, poke nose please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Paul Smith @Paul, 2013-05-30
@Remasik

Your script is not where the system is looking for it. Put it in /usr/bin/, write the “translate” command in hotkeys, without .sh and other things.

A
avalak, 2013-05-30
@avalak

[ -d "$HOME/bin" ] && PATH="$HOME/bin:$PATH"

If .profileor .bash_profilenot this line, then add it and create a directory ~/bin. You need to either re-login or re-read the settings with the command source ~/.profile. After that, the system will see scripts from bin. Alternatively, you can specify the full path to the script.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question