How to assign a keyboard shortcut to a specific New Window template in Terminal.app?

1

2

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.

emmby

Posted 2010-03-10T17:42:00.390

Reputation: 977

If this is important to you, please file a bug report: http://developer.apple.com/bugreporter/

(If you don't already have one, it requires a developer account, but it's free.)

– Chris Page – 2011-10-12T04:59:34.917

Answers

2

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.

Daniel Beck

Posted 2010-03-10T17:42:00.390

Reputation: 98 421

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 – 2011-11-10T11:06:10.397

1

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

user31752

Posted 2010-03-10T17:42:00.390

Reputation:

Thanks mankoff. Not a bad idea, but I was hoping for something that wouldn't require a launcher – emmby – 2010-03-26T03:37:05.817

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... – None – 2010-03-29T22:29:11.147

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. – None – 2010-03-29T22:30:05.623

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 – 2011-11-10T10:55:46.167

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 – 2011-11-10T11:10:10.750

0

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.

user31752

Posted 2010-03-10T17:42:00.390

Reputation: