I have a template set up in Snow Leopard's Terminal.app to create a new window or tab with my preferred emulation settings for a particular host that I use.

I'd like to assign a keyboard shortcut to that template so that I can quickly create a new window with those settings.

I tried using the Keyboard Shortcuts System Preference pane to do it. I can assign the shortcut key to the MyTemplate submenu, but it doesn't work when I try to use it. I suspect because the MyTemplate is listed in multiple submenus -- one for New Window and one for New Tab.

How can I assign a keyboard shortcut to my new fancy template?

PS. I do NOT wish to change my default (cmd-N) template.


Open Automator, create a new Service with the following Run AppleScript action (no input):

tell application "Terminal"
    activate # switch to Terminal, launch if necessary
    tell application "System Events"
        keystroke "t" using command down # open a new tab
    end tell
    set current settings of selected tab of front window to first settings set whose name is "MyTemplate" # switch settings to your template
end tell

The service will be accessible from the Services menu, and you can assign a shortcut in System Preferences » Keyboard » Keyboard Shortcuts » Services

Edited to add: You can specify whether you want this service to work globally by specifying any application or Terminal in Automator. Both work with this code, it just determined in which applications the service shows up.

  • If you can live with a new window instead of a new tab, you can bypass the whole System Events GUI scripting part and just use do script "" – Terminal will open a new window for scripts launched from AppleScript if no tab or window object is specified with an in clause. – kopischke Nov 10 '11 at 11:06

You could save a setup into .term file and then use a third party launcher (Quicksilver?) to start it from there.

  • Thanks mankoff. Not a bad idea, but I was hoping for something that wouldn't require a launcher – emmby Mar 26 '10 at 3:37
  • You could do it with Spotlight... Still uses a launcher but at least not 3rd party. Sorry I can't think of much else at this point... – user31752 Mar 29 '10 at 22:29
  • Hmm.. You could do it without a keyboard shortcut, using your mouse instead. Drag the .term file into the Dock, launch by clicking? I guess you can also use a keyboard shortcut to access the dock too. – user31752 Mar 29 '10 at 22:30
  • Any utility able to assign a hotkey to a specific file will do (I use Alfred with the PowerPack). One caveat: this will not reflect changes you make to the profile in Terminal.app unless you remember to export the profile every time. – kopischke Nov 10 '11 at 10:55
  • If you don’t want to use a launcher, OS X’s Automator services will do too (see @DanielBeck’s answer) – create an Automator service opening the .term file (you can do that entirely with the inbuilt actions – no AppleScript needed) and assign it a keyboard shortcut in System Preferences. Note however Automator services tend to react very slooooowly at first launch – a dedicated launcher would probably be much more reactive. – kopischke Nov 10 '11 at 11:10

I assume your suspicion is correct that the same item in multiple sub-menus is the problem. I've assigned keyboard shortcuts to submenu items without any problem when the string was unique.

Therefore, one approach would be to remove the "New Tab" menu item entirely. Try editing the user interface element that defines the menu.

Use plutil and the command line to make a compiled NIB editable, or there are some hints online about copying the compiled NIB into an application that uses uncompiled NIBS and then using Interface Builder.app.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.