Is there a way to add a keyboard shortcut for a terminal command in OSX. Basically most of the times i open the terminal app in MAC in order to ssh into a certain server foo. What I want to do is add a keyboard shortcut (say ^k) so that on a terminal when I do that, it runs "ssh foo" in the terminal.

Thanks

PS: I think if there is something for the xterm in linux then it should work for the terminal too. So this might not be an OSX specific question.

PS2: I want the shortcut to do carriage return with the "ssh foo". If its just "ssh foo", then I can write an alias in .bashrc. My goal is to minimize the number of keystrokes I've to do at the end of the day.

link|improve this question
feedback

migrated from stackoverflow.com Jul 5 '11 at 9:22

This question came from our site for professional and enthusiast programmers.

4 Answers

These solutions are not perfect, but could help. I only have Russian interface, so you'd have to figure specific option names for yourself.

Solution 1.

Terminal - Settings - [Second tab] - Shell - Command to run on launch

Solution 2.

Terminal - Settings - [Second tab] - Keyboard, it will allow you to use special keys to run shell commands (not ctrl-k, though)

enter image description here

enter image description here

link|improve this answer
Basically i want it to do "ssh foo" and a carriage return at the keyboard shortcut. Otherwise i could just put up an "alias" in .bashrc and use it. I got excited about the second solution but unfortunately terminal does not save carriage return (in the keyboard settings entry) after writing "ssh foo". – Injun Joe Jul 5 '11 at 6:57
Oh and about the first solution. I used to use it earlier but clicking on shell and then new window was more cumbersome than just starting up a new shell and finding the command from my command history (through ctrl-r). Unless there is a shortcut to start a particular type of terminal, I find it useless. – Injun Joe Jul 5 '11 at 7:00
this is strange, because my terminal actually starts midnight commander (mc) automatically when launched from Dock, for instance. – etranger Jul 5 '11 at 8:16
Oh yes, the first solution would work. The problem is that if I do not want to do click "shell -> new window", I would need to save it in my default shell. But I do not want to start "ssh foo" and exit everytime when I do not want to do it. – I J Jul 5 '11 at 16:54
feedback

I don't believe there is a way to create a keyboard shortcut like that, however there are a couple of options.

  1. TextExpander allows you to type a small set of letters and have it 'expand' to the whole thing. This could work, not sure if it is supported in Terminal, but it could work.

  2. Since most of the time you run this command in Terminal first, you can go to Terminal > Preferences > Startup and set your 'Shell Opens With' command to be what you want. Then, the few times you don't want to, simply exit out of ssh...a lot easier then typing the command.

link|improve this answer
feedback

I'm using TextExpander for exact this purpose: Screenshot TextExpander

TextExpander macro:

ssh -l user -p 99999 void.example.com%key:return%
echo "some command"%key:return%

Highly recommended. Unfortunately it's not free, and there other ways for sure, but it works well.

Edit: This ssh connection uses a keyfile, so theres no password required.

Edit2: This looks like another solution to your problem: Terminitor

link|improve this answer
feedback

Use iTerm2. It has the ability to do exactly what you want: define a profile which runs a certain command when starting the terminal, and assign a shortcut key to that profile - so that pressing the key combination opens a new terminal tab ssh-ed into your server.

link|improve this answer
The original asker wants to be able to do this in Terminal, not by using a third party application... – nhinkle Jul 5 '11 at 19:43
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.