Redirecting Terminal.app to iTerm.app

6

Is it possible to redirect an app in Mac OS X to another app?

If not, can you redirect Terminal.app to iTerm.app, so every app that wants to open a Terminal window, instead opens an iTerm window.

For example when something runs:

  • tell application "Terminal" in AppleScript
  • open -a Terminal
  • open -a /Applications/Utilities/Terminal.app
  • /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal
  • open -b com.apple.terminal
  • etc.

Examples when this happens:

  • BBEdit: Clicking "Run in Terminal"
  • Alfred: Creating a shell-extension and toggle "Silent" off and run it

Tyilo

Posted 2011-08-05T20:19:12.643

Reputation: 2 345

1Which app wants to open Terminal.app? – slhck – 2011-08-05T20:24:19.987

When something runs tell application "Terminal" in applescript, when something runs open -a Terminal, open -a /Applications/Utilities/Terminal.app, /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal or open -b com.apple.terminal etc etc... – Tyilo – 2011-08-05T20:28:58.110

May I ask why? You cover probably all cases I could think of, but in order to do that, you'd need to effectively "turn" Terminal.app into iTerm.app, either by changing the Info.plist file located within Terminal.app (read more about that here). Or just move the Terminal executable away and replace it with iTerm's executable. Don't know if that will work as expected though.

– slhck – 2011-08-05T21:03:21.483

Because I normally use iTerm2 and never Terminal, only when another program oens it. – Tyilo – 2011-08-05T21:12:03.423

2To be honest, I've never seen any program opening a Terminal so far. Everything you mentioned above involves manually opening, so it shouldn't be hard to change these lines to iTerm2 (which is different from iTerm, by the way). Can you be a bit more specific, maybe? I still don't know which use case you are talking about. – slhck – 2011-08-05T21:15:58.570

1@slhck I surely hope that Apple would prevent (by checksums, codesigning and sandboxing) replacing Terminal´s executables with other code! And I totally agree, I´ve never seen other .apps open Terminal; only .command files could be an issue, but you can change the "open with…" assignment there. – Asmus – 2011-08-06T11:37:55.610

@Asmus & slhck I'm using some applications that does this, BBEdit and Alfred are the only one's I can think of right now – Tyilo – 2011-08-06T12:15:52.940

Maybe we should investigate those specific issues then -- can you clarify your post a bit? (What you're doing in Alfred/BBEdit)

– slhck – 2011-08-06T13:14:04.503

Answers

5

As said in the comments above, you won't be able to change that on a large scale basis. Applications calling Terminal.app will do that by calling its Bundle identifier, com.apple.terminal. You'd have to change this to "fake" the Terminal and redirect to another one. Is that's possible? I highly doubt so.

This means that every application calling Terminal will have a setting for the bundle identifier used. Some will probably have that hardcoded, others should allow changing it, either through Preferences or through a preference list setting.


How to make BBEdit use another Terminal

For BBEdit, that's relatively easy according to the release notes. This is for version 8.7 though, and I can't find it in the "Experts Preferences" of version 10 anymore. Maybe they've removed the feature.

defaults write com.barebones.bbedit Misc:TerminalBundleIDOverride "com.googlecode.iTerm2"

Just replace com.apple.Terminal with the bundle identified of the other terminal emulator, e.g. com.googlecode.iterm2 for iTerm2.

A similar entry can be found on secrets.blacktree.com, although it doesn't appear to be working (I've never seen a -bundleid datatype in defaults).

The best idea would be to bring up a support request with BBEdit's developers.


How to make Alfred use another Terminal

Alfred's shell extensions use the terminal emulator you specify, according to the help.

You can select to use the OS X Terminal.app or iTerm, as well as your prefix for Shell commands in the Alfred preferences.

enter image description here

It didn't work for me at first, so I had to delete iTerm.app, delete Alfred and its preferences/caches, then reinstall iTerm2. This is explained in the Alfred support forums.

slhck

Posted 2011-08-05T20:19:12.643

Reputation: 182 472

In BBEdit 11, you can use:

defaults write com.barebones.bbedit TerminalBundleID -string "com.googlecode.iterm2" – mediaczar – 2015-07-17T15:19:13.207

Isn't it supposed to be defaults write com.barebones.bbedit Misc:TerminalBundleIDOverride "com.apple.Terminal" ? (Removed p and straighten quotes) Neither with or without "p" it didn't work in BBEdit 10, but with Alfred I just had to change it in the Terminal / Shell dropdown – Tyilo – 2011-08-06T14:41:28.470

Whoops, copy/paste error. Doesn't appear to be working anymore (see edits above). – slhck – 2011-08-06T15:49:03.997