How to run a particular command at startup?

I don't understand scripts or how to make them or how to run them. All I want to do is run the command xmodmap -e "keycode 112 = Delete" when my computer starts. When I run this command in terminal, it remaps the PgDn key to be a second Delete key. But then I have to run it again every time I start the computer. How can I do this? I've tried adding it as a line in the rc.local file but it doesn't work.


Solution 1:

You can make it run at boot by adding it in startup applications. Open startup applications from the dash. Click 'Add' and put xmodmap -e "keycode 112 = Delete" in the 'Command' field. Give it a name and comment if you want. Click 'Add' and login again.

enter image description here

Solution 2:

Seth's solution is a high-level solution that works fine as long as you don't change the desktop environment to something more exotic. To be on the secure side you might want to choose a method that acts at a lower level:

Open up a terminal (CTRL + ALT + T) and execute the following command:

echo "xmodmap -e \"keycode 112 = Delete"\" >> $HOME/.bashrc

This appends xmodmap -e "keycode 112 = Delete" to your .bashrc file and thus executes it on each login.

Edit: As Mik pointed out this might not be the best way of setting xmodmap up. See here for a better method.