I want to bind a shortcut to run a command in Terminal with text that I selected while web browsing. How could I do this?
MacOS – How to execute Terminal command using selected text
macosterminal
Related Question
- How to have different colors in each Terminal window
- MacOS – Running Terminal Command and Opening App Twice with Alfred
- In Terminal, how to erase typed command quickly
- MacOS – Bind keyboard key (like F16) to execute command
- Execute terminal command “rsync” from BetterTouchTool
- MacOS – How copy text into Terminal command line zsh
- Programmatically Get Terminal Scrollback Text
Best Answer
You can achieve this by making an automator workflow and saving it as a service.
Open Automator.app, choose to make a Service.
In the top menu set "Service receives selected" to "text" in "any application".
From the Actions, Library menu search for "Get Value of Variable" and drag to the right in the workflow area. Again in the Actions, Library search for "Run AppleScript" and drag to the workflow area.
In the "Run AppleScript" action enter the flowing code:
Add a variable by clicking on the little double bar icon at the bottom of the window and then right-clicking in the variables frame to create a new variable. Name your variable anything you like. When your done your workflow should look like below. Save it and name it something like "Run in Terminal". Now when your in a web browser you can right click and navigate to Services and you will see your "Run in Terminal" command, which will open up terminal and run the highlighted text.