4

I'd like to have a keyboard shortcut to open a new terminal from wherever I am. A default shell in my default home directory would be great. I've been trying for a while to make this happen, but no luck so far. Things that I've tried:

1) syspref -> keyboard -> shortcuts -> services, select 'new terminal at folder'. Result: it just beeps and does nothing

2) syspref -> keyboard -> shortcuts -> app shortcuts -> create a new item that links to the 'Terminal' application. Result: beeps and does nothing

3) From automator, create a new service that accepts no input and launches 'Terminal', bind the new service from the keyboards shortcut menu. (followed these instructions). This kind of works, but only some times (see update)

What am I doing wrong ?

Update

Solution 3 kind of works but it has two drawbacks:

  • it only works if some window is focused, it will NOT work if you don't have any window or if no window is currently in focus. Furthermore even if a window is focused, it apparently has to be the right kind of window, e.g. for some reason it does not work if chrome is focused, but it will work if gvim is focused, WTF?.
  • if a terminal window is already open it will just focus the existing terminal and bring it on top, I'd like to have a new, fresh terminal window appear (ok I guess I can just do ctrl-command-t to bring it in focus and then control-n for new window, but it kind of sucks)
1
  • Number 3 works I used the shortcut (Control-Command-T). You might consider looking at this question. apple.stackexchange.com/q/54/47196. I personally use alfred for this (which is one of the answers in that question)
    – FDinoff
    Feb 2, 2014 at 22:08

3 Answers 3

3

You can create a service like this:

Then give it a shortcut from System Preferences.

There is a delay of maybe 0.1 - 1 s before Automator services are run, and at least on my installations of 10.7 and 10.8, the shortcuts for services didn't always work until I hovered over the services menu from the menu bar. You might also use FastScripts to assign a shortcut to the script, or use a private.xml like this with KeyRemap4MacBook:

<?xml version="1.0"?>
<root>
  <vkopenurldef>
    <name>KeyCode::VK_OPEN_URL_SHELL_TERMINAL</name>
    <url type="shell">osascript -e 'tell app "Terminal"' -e 'do script ""' -e activate -e end</url>
  </vkopenurldef>
  <item>
    <name>test</name>
    <identifier>test</identifier>
    <autogen>__KeyToKey__ KeyCode::F5, ModifierFlag::NONE, KeyCode::VK_OPEN_URL_SHELL_TERMINAL</autogen>
  </item>
</root>

If others look for a way to open Terminal and only create a new window if there are no existing windows, you can use a private.xml like this with KeyRemap4MacBook:

<?xml version="1.0"?>
<root>
  <vkopenurldef>
    <name>KeyCode::VK_OPEN_URL_TERMINAL</name>
    <url>file:///Applications/Utilities/Terminal.app</url>
  </vkopenurldef>
  <item>
    <name>test</name>
    <identifier>test</identifier>
    <autogen>__KeyToKey__ KeyCode::F5, ModifierFlag::NONE, KeyCode::VK_OPEN_URL_TERMINAL</autogen>
  </item>
</root>

Or if you have bought the Powerpack for Alfred 2, you can create a workflow like this:

1
1

There's a bug that prevents newly assigned keyboard shortcuts from working until you view the Services submenu in an application. Alas, that workaround doesn't work for the Terminal services, because they never appear in the Services submenu—they only appear in the contextual menu.

For other Services, another workaround is to assign a key to the menu item via App Shortcuts instead of via Services (both are in the Shortcuts tab in the Keyboard system preference panel). However, although the shortcut appears in the contextual menu in Finder, and it even works while the menu is visible, it has no effect unless you're viewing the contextual menu.

1
  • So frustrating, but I see this same bug on 10.10.5. Have to view the services submenu before the keyboard shortcut works.
    – supergra
    Mar 2, 2016 at 18:06
0

1) should work, but the Folder has to be selected (focused). It's not enough to just be in a folder and have nothing (or a regular file) selected.

Select a folder in finder, if you activated the checkbox under Syspref > Keyboard > Shortcuts > Services > new terminal at folder you can also see the menu entry at Finder > Services.


A simple shortcut to Terminal.app (or any other) could be done in Automator:

create a new service, select no input at service receives, add the Launch Application action and select Terminal.app. Now save the the service and go to System Preferences > Keyboard > Shortcuts > Services, the just created service should appear at the bottom with the name as you saved it. Add a keyboard shortcut and you then can start Terminal from any app with that.

2
  • but I don't want it to be in a folder, all I want is a fresh new terminal window, I'll update the question. Feb 2, 2014 at 21:49
  • Sorry I got the question wrong. The service is meant to be a Finder service to open a terminal with the selected directory as working directory. I updated my answer with a quick solution to create a simple shortcut to any application using Automator. If it just beeps and does nothing, try to assign a different shortcut (like ⌘+F1) to make sure it is not already assigned.
    – nappo
    Feb 3, 2014 at 8:09

You must log in to answer this question.

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