Score:0

Keyboard shortcuts don't see my custom executable

cn flag

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?

ar flag
When you setup the keyboard shortcut, enter `/full/custom/folder/path/of/your_script`.
IgnoranteX avatar
cn flag
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`...
ar flag
Try `/home/your_username/mf/script`. That is called the **full path**.
IgnoranteX avatar
cn flag
No way, still the keyboard shortcut has no effect whatsoever even with the full path. BTW thanks for the help.
Score:0
sa flag

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.

Score:0
cn flag

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.

IgnoranteX avatar
cn flag
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.
vanadium avatar
cn flag
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.
IgnoranteX avatar
cn flag
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?
vanadium avatar
cn flag
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.
IgnoranteX avatar
cn flag
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...
vanadium avatar
cn flag
I must apologize: it is `~/.local/bin`, not `~/.local/share/bin`. I corrected my answer. Remove the addition to the path. Instead, log out/back in. Both directories are automatically added to the path if they exist. Note that for a full path, you cannot use bash expansion symbols like ~ nor variables. Added this explicitly now. One of the two options now definitely should work, so please accept the answer if it does.
IgnoranteX avatar
cn flag
Ok. I accept your answer since you look very confident but still both Options don't work using shortcuts to invoke. I have faith that my problem is in the content of the very bash code I wrote: `#!/bin/bash -l conda run -n vision python anotherfile.py` Do you see an issue here?
vanadium avatar
cn flag
Your real problem appears not that the shortcut does not see your custom script, but that you do not see output of the terminal program when you start it with a shortcut. Take the habit of asking directly about your real problem (Problem X) instead of about what you expect will be the solution (Problem Y). That leads to direct help and avoids lengthy discussions. Thanks for accepting this answer to this question. For seeing terminal output with a shortcut key, launch your terminal emulator and have it execute your command through the command line.
IgnoranteX avatar
cn flag
Well, the script is not expected to print any output but to open the camera of my pc. As I said already the script works fine in the command line but it doesn't from the shortcut (I had also another script that modifies the keyboard mapping and it doesn't work either). In any case, thanks for the suggestions, next time I will be specific from the beginning.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.