Custom Terminal Applescripts for Alfred to Fix iTerm Behaviour

I have put together some custom terminal applescripts in the last week for those that use Alfred for the Mac and iTerm. For those of you that have been finding finding issues with some of the newer versions of iTerm (including iTerm 2, and 2.9) and getting them to work reliably with Alfred, all this has required is an update to the Applescripts that are being used by Alfred to keep up with the (seemingly rapid) changes to the functions iTerm exposes with Applescript. Some issues I have faced go so far as iTerm simply not opening (where there were multiple iTerm binaries on the system), and sometimes commands not being passed through to newer versions.

There are two versions of the script available:

Each of these can be inserted into Alfred by following these steps:

  1. Load the Alfred control panel
  2. Click the Features Button/Tab
  3. Click on the “Terminal/Shell” menu on the left hand side
  4. Select “Custom” under application, and replace the text in the new box that appears with the code as per the version of iTerm you are running.

iTerm 2.1 Branch Custom Terminal Script Features:

The 2.1 branch script is very basic and just corrects the opening of iTerm and creating a new session properly.

iTerm 2.9 Branch Custom Terminal Script Features:

The 2.9 Branch goes a bit further to utilise some of the new features of iTerm 2.9 (which is in beta at the moment and can be downloaded if you are feeling adventurous from the iTerm download page). The script has been designed to achieve the following:

  • Open the correct iTerm binary under /Applications/iTerm.app regardless of if another iterm/iTerm binary exists on the system
  • Always create a new tab/session, unless iTerm is not running, in which case use the default session.
  • If the user has selected to not create a default session on iTerm startup, detect and create a default session.

Future Updates:

As new versions come out of the 2.9 branch I will keep the scripts up to date and post details to the official AlfredApp community forum post, if anyone finds issues with the 2.1 branch please let me know either there, or in a comment below and I will test things out.

If you would like to look at/contribute to the official repository please check it out on Github –> https://github.com/s…ipts-for-alfred.

As always, I welcome ideas/thoughts/feedback etc.

Cheers,
Stuart