1

Simple I am looking for a way to map a keyboard key to a unix command. It could be as simple as literal as opening up terminal and pasting a required bit of text.

  • What sort of key? I assume you want a modified key, and don't want, say, the <kbd>L</kbd> key to not type a l but rather run sudo rm -Rf / – Daniel Feb 9 '12 at 1:30
1

You could use a tool like Keyboard Maestro but it might be a bit overkill.

If you just want to execute a command in Terminal and close the window again:

  • Put command in a shell script
  • Make it executable (chmod +x ...)
  • Move shell script to a convenient place (e.g. our Desktop)
  • run shell script/command by double click
  • I just want to run a command (eg pwd) in terminal via a keyboard key. When you press the key it could open terminal and paste in PWD and then close terminal, but this would be sloppy. – ThomasReggi Oct 9 '11 at 20:52
  • Maybe a shell script is ok then, I've extended the answer accordingly. – nohillside Oct 10 '11 at 6:09
  • there is the unix alias command. i have the h key set to type out my help.txt file. alias h='cat ~/help.txt'; alias ll='\ls -albhFG'; alias ls='ls -FhG'; alias more='less'; alias mv='mv -i'; alias rm='rm -i'; alias top='top -o cpu'; You need to press return, but one letter commands are not too bad. – historystamp Feb 20 '19 at 6:30
0

Automator has a "Run Shell Script" action.

  1. Open Automator and create to new Quick Action
  2. Search for shell in the actions menu
  3. Drag "Run Shell Script" to the right panel
  4. Save as "Run Unix command"
  5. Open Keyboard and go to Shortcuts
  6. Scroll to "Services" and scroll to the bottom
  7. Bind "Run Unix command" to whatever you want.

See also this answer.

You must log in to answer this question.

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