Say I am in a Finder window (eg: ~/Documents/code ) and I want to be able to use a keyboard shortcut to open a terminal window with the prompt
user@computer: ~/Documents/code$
Most of the questions are answered using mouse.
finderkeybindings
Say I am in a Finder window (eg: ~/Documents/code ) and I want to be able to use a keyboard shortcut to open a terminal window with the prompt
user@computer: ~/Documents/code$
Most of the questions are answered using mouse.
Best Answer
In System Preferences > Keyboard > Shortcuts > Services under Files and Folders there is a New Terminal at Folder shortcut which you can assign a keyboard shortcut to; however, it only appears on the Finder > Services menu, or the right-click context menu, when a Folder is selected. So if you have a Finder window open but no additional folder selected, it is not available. This may be fine for one's particular usage, but if not, then here is an alternative.
For example, say you have a Finder window open to your Downloads folder, which is selected in the Sidebar, and you want to open a Terminal window there. Well the built in service isn't available because an individual Folder isn't selected and what's selected in the Sidebar doesn't count...
One way to open a Terminal window at the location of the current Finder window, using a keyboard shortcut, is to use AppleScript in an Automator Service (Quick Action in macOS Mojave), then assign it a keyboard shortcut in: System Preferences > Keyboard > Shortcuts > Services > ...
Create an Automator Service adding a Run AppleScript action, then replace the default code with the example AppleScript code shown below.
Save the service as e.g. Open Terminal Here with the settings as shown in the image below. Then assign it a keyboard shortcut. It should show under the General section of the aforementioned path.
Example AppleScript code:
As an added bonus, you can also use the example AppleScript code saved as an AppleScript application in Script Editor and place it in the Toolbar of Finder, thus allowing one to click the icon to open a Terminal window at the current location when one wants versus using the keyboard short assigned to the Automator service. No third-party app required!
1 Required in later versions of OS X/macOS.
Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors.