0

On Ubuntu 22.04 I have an executable (bash) file in custom folder scripts in the home. The path of the latter is properly included at the end of the .bashrc file (and also at the end of the .profile one, just to be sure) with the line export PATH="$PATH:/home/username/scripts". The command runs correctly in a terminal shell but not if I invoke it through a keyboard shortcut properly set via Settings. Edit: The same issue shows up on two different computers which recently had an OS fresh install and with different kinds of bash executables.

Where do I modify the path used by keyboard shortcuts?

4
  • 1
    When you setup the keyboard shortcut, enter /full/custom/folder/path/of/your_script.
    – user68186
    Commented Oct 6, 2022 at 14:11
  • Your suggestion doesn't seem to work. If my folder is "mf" in the home and the script is called "script", I tried both mf/script and ~/mf/script...
    – IgnoranteX
    Commented Oct 6, 2022 at 14:21
  • 1
    Try /home/your_username/mf/script. That is called the full path.
    – user68186
    Commented Oct 6, 2022 at 14:53
  • No way, still the keyboard shortcut has no effect whatsoever even with the full path. BTW thanks for the help.
    – IgnoranteX
    Commented Oct 6, 2022 at 15:03

2 Answers 2

0

Modifying the path used by keyboard shortcuts is not the solution to your problem. There are two possibilities:

Option 1. In the "Command" field for your keyboard shortcut, you specify the full path to your executable, e.g. /path/to/custom_folder/some_executable. Note that you cannot use bash expansion (~) nor variable, so the path must be spelled out explicitly.

Option 2. You place the executable in a directory that is in the search PATH. Type printenv PATH to see all these directories. More precisely, you place it in ~/.local/bin or in ~/bin if you are the only one running the command. If the command needs to be available for all users on the system, place it in /usr/local/bin. The latter assumes you have administrator rights on your machine.

Instead of effectively moving the executable in one of these directories, you also can place a symlink or a wrapper script there if you prefer not to move the executable from its current location.

9
  • Option 1 doesn't work in my case as I commented to user6818. I guess there must be a bug somewhere. The OS has been fresh installed 2 days ago and I didn't mess much around. Any input? Option 2 is a workaround that will work since I have defined other shortcuts that work properly for commands in ~/.local/share/bin but I wanted to keep my scripts in the home.
    – IgnoranteX
    Commented Oct 6, 2022 at 17:09
  • It might be a bug, but definitely not in the operating system. Option 2 is not a workaround: it is common good practice. I have no further ideas because you do not provide any detail.
    – vanadium
    Commented Oct 6, 2022 at 18:47
  • I edited the question giving some more details of what I need, if you need something else, just tell me specifically what you need, please. Option 2 would be for me the last resort, since I don't want to bury my scripts in a folder which is not in the home. It might be appealing to me only if there is a way to clone my folder in the home in the /usr/local/share/bin in such a way that the clone updates automatically whenever you modify the one the home. May you help me in this direction? is it considered a clean for organizing one's own scripts?
    – IgnoranteX
    Commented Oct 7, 2022 at 10:13
  • The clean way to organize your scripts is to place them in ~/.local/share/bin, but also ~/bin is valid (the "older" way, which is why I did not mention it). So that solves your concern you do not want the scripts "buried". I will add that directory to the answer now. Another way not to "bury" (or to "unbury") is creating a symlink, of course.
    – vanadium
    Commented Oct 7, 2022 at 11:45
  • I changed the location of my executable in ~/.local/share/bin and added the location in the path (I had to create this folder since it was not there already). Again the file doesn't load when invoked with a keyboard shortcut. Wierdly, to me, the symlink option seems to be the only one left...
    – IgnoranteX
    Commented Oct 7, 2022 at 12:12
0

Here is a simple example to make the process mentioned by @vanadium clearer:

Suppose that you have a read_this.sh bash file that reads your clipboard aloud:

txt=$(xclip -selection clipboard -o)
clean_txt=$(tr -d "\"'" <<< "$txt")
echo "(SayText \"$clean_txt\")" | festival '(voice_cmu_us_slt_arctic_hts)' --pipe
  1. Copy the file in the /bin/ folder (do this command from the folder of the file):

    sudo cp read_this.sh /bin/read_this

  2. Add a shortcut with command bash read_this to the Keyboard Shortcut panel in the settings.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .