I would like to run a shell script on the press of a button. The script works if I run it like usually:
sh script.sh. But assigning a shortcut to it doesn't work.
How would you do this in Xubuntu 14.10?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
I'm pretty sure the problem is the
~. That is a shell (commandline shell) feature and the keyboard shortcuts are handled by the graphical shell. I don't think that
$HOME will be expanded correctly there. So, instead of
That assumes you have made the script executable. If not, use
sh should be enough since the
$PATH is also read by graphical shells as far as I know. If that also fails, try with the full path but I doubt it will be necessary:
Awesome post. I've been searching for a way to do this for the last few versions of ubuntu (currently on 19.04)
Using the full path is what did it. Thank you. What worked for me was the following...
I was looking for a way to set a hotkey to insert the date / time into whatever document I had open.
I found a script online and made a few minor changes (primarily the hotkey association because I didn't like their choice since it was a key combo that was already used by ubuntu) to one I wanted and which was also available.
Created a file called 'insertTimestamp.sh' in my root directory.
I then pasted (and slightly modified) the code to my liking...
Copy/paste the code below
# ! /bin/sh xdotool keyup "super+t"; # needed to refresh the status of the request. simulates letting go of the hotkey super+t keys, otherwise it interferes with ctrl-v paste function date '+%Y-%m-%d %H:%M:%S' | tr -d "\n" | xsel -i -b; # add the date/time to the clipboard xdotool key "ctrl+v"; #simulate a ctrl-v # xdotool keydown "super"; #unpretend the user let go of the super key
Once I pasted the above into the file and saved it, it was necessary to change the permissions of the file
chmod u+x ~/insertTimestamp.sh
Once done, you simply need to search for "keyboard" => choose Keyboard => Go to Application Shortcuts Tab => Add => For "Command" type
sh the/full/path/insertTimestamp.sh (update your full path) => Set keys as super+t.
I hope this provides a decent example of how to set this up.