Ben Szymanski

Software Engineer • Vlogging about efoils, tech and music • πŸ‡ΊπŸ‡Έ & 🐊

The Problem'

One of my favorite and often used applications on macOS X is Terminal.app. In earlier versions of macOS X, Terminal was kind of ugly and a little scary, but ever since 10.6 (from what I can remember), thing have been greatly improved.

One of the most annoying things about using a command-line environment though, is typing all of those commands in. It's especially painful if you need to carry out a task again and again. Open a new Terminal window, type commands, close Terminal window (or restart your machine and loose whatever you had running in Terminal).

To publish a new article or update content on this website, I have to type the following commands:

$ cd /Library/Python/3.4.2/smashingfiasco/bin
$ source activate
$ cd /Applications/MAMP/htdocs/sfiasco

The first changes the prompt the location of my Python installation, and then virtual environment directory. The second activates my Python virtualenv for this website. The third changes to my website content directory.

It's not hard, and I have it memorized by now, but it's just that bit more pain that is sometimes off-putting and makes me lazy and not update this website. Usually, I'll just leave the Terminal window open forever, unless I have to restart, in which case, I loose everything and then have to retype those three commands above again.

A Nice Solution

In the preferences window of Terminal.app, you can create different Terminal profiles (several already exist) as presets that you can use again and again. I have known about the Startup > Run command: present for a while and I have often thought about using it to store those three commands above that I have to type repeatedly, but wasn't quite sure if you could actually put three commands in that textbox.

I can confirm that you CAN put more than one startup command into this textbox and Terminal.app will run all three of them.

The key is to separate each command with a semi-colon.

In my case, I''d write the following in:

cd /Library/Python/3.4.2/smashingfiasco/bin; source activate; cd /Applications/MAMP/htdocs/sfiasco

This works perfectly.

Creating Profiles

The final key to Terminal start-up command bliss is to create a separate profile for each set of these start-up commands that you need to carry out (before you can get started on whatever you need to do).

Back in Terminal.app > Preferences / Profiles, you can select any one of the existing profiles (I typically use Pro), and then duplicate it by opening the gear fly-out menu.

Modify the duplicated profile to include your start-up commands, and then the next time you need to type those commands, you can easily click through the Shell > New Window > yourprofile menu items.

Proudly powered by Pelican, which takes great advantage of Python.