Is there a keyboard shortcut (hotkey) to open Terminal in macOS?

吃可爱长大的小学妹 提交于 2019-11-29 18:50:06

I tested the following procedure under OS X 10.11.3 (El Capitan).

Launch Automator. Create a document of type “Service”. In the document, add a “Run AppleScript” action. Here's the AppleScript to paste into the action:

on run {input, parameters}
    tell application "Terminal"
        if it is running then
            do script ""
        end if
        activate
    end tell
end run

Set the “Service receives” popup to “no input”. It should look like this overall:

Save the document with the name “New Terminal”. Then go to the Automator menu (or the app menu in any running application) and open the Services submenu. You should now see the “New Terminal” service:

If you click it, Terminal should open a new window.

To assign a keyboard shortcut to it, choose the “Services Preferences…” item from that menu. (Or launch System Preferences, choose the Keyboard pane, then choose the Shortcuts tab, then choose Services from the left-hand list.) Scroll to the bottom of the right-hand list and find the New Terminal service. Click the right end of the New Terminal row and press your preferred keyboard shortcut:

Now you should be able to press your keyboard shortcut in most circumstances to get a new terminal window.

As programmers we want the quickest, most fool-proof way to get our tools in order so we can start hacking. Here are how I got it to work in MacOS 10.13.1 (High Sierra):

  • Option 1: Go to System Preferences | Keyboard | Shortcut | Services. Under Files and Folders section, enable New Terminal at Folder and/or New Terminal Tab at Folder and assign a shortcut key to it.

  • Option 2: If you want the shortcut key to work anywhere, create a new Service using Automator, then go to the Keyboard Shortcut to assign a shortcut key to it. Known limitation: not work from the desktop

Notes:

  • If the shortcut doesn't work, it might be in conflict with another key binding (and the OS wouldn't warn you), try something else, e.g. if ⇧⌥T doesn't work, try ⇧⌘T.
  • Don't spell-correct MacOS, that's not necessary.

iTerm2 - an alternative to Terminal - has an option to use configurable system-wide hotkey to show/hide (initially set to Alt+Space, disabled by default)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!